Hi, this is Shunchi!

  • Home

  • Tags0

  • Archives267

  • Categories0

  • Curricula

  • DSA

  • LeetCode_Notes

  • Interviews

  • General

  • Resume

137. Single Number II

Posted on 2020-04-06 | Edited on 2021-01-22

https://leetcode.com/problems/single-number-ii/

Bitwise operators

1
2
3
4
5
6
7
8
9
10
class Solution {
public int singleNumber(int[] nums) {
int once = 0, twice = 0;
for (int num : nums) {
once = (~twice) & (once ^ num);
twice = (~once) & (twice ^ num);
}
return once;
}
}

<1…239240241…267>
ShunchiZhou

ShunchiZhou

267 posts
RSS
GitHub E-Mail Gitbook Linkedin
© 2024 ShunchiZhou
Powered by Hexo v5.4.0
|
0%