首页 > 学院 > 开发设计 > 正文

LeetCode:Single-Number

2019-11-08 03:01:25
字体:
来源:转载
供稿:网友

Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

iclass Solution {public: int singleNumber(int A[], int n) { int result = A[0]; for(int i=1;i<n;++i) { result = result^A[i]; } return result; }};
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表