diff options
Diffstat (limited to 'top-interview-questions/easy/array/05_single_number.cc')
| -rw-r--r-- | top-interview-questions/easy/array/05_single_number.cc | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/top-interview-questions/easy/array/05_single_number.cc b/top-interview-questions/easy/array/05_single_number.cc new file mode 100644 index 0000000..ad55712 --- /dev/null +++ b/top-interview-questions/easy/array/05_single_number.cc | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | class Solution { | ||
| 2 | public: | ||
| 3 | int singleNumber(vector<int>& nums) { | ||
| 4 | int x = 0; | ||
| 5 | for (int n : nums) { | ||
| 6 | x = x ^ n; | ||
| 7 | } | ||
| 8 | return x; | ||
| 9 | } | ||
| 10 | }; | ||
