Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3559b30

Browse files
Merge pull request MisterBooo#113 from ztianming/patch-6
Update 0137-Single-Number-II.md
2 parents 9388678 + 5c8e809 commit 3559b30

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

‎0137-Single-Number-II/Article/0137-Single-Number-II.md‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,45 @@
4646

4747
![](../Animation/137.gif)
4848

49+
### 代码实现
50+
#### C++
51+
```c++
52+
class Solution {
53+
public:
54+
int singleNumber(vector<int>& nums) {
55+
int one=0, two=0;
56+
for(int n:nums)
57+
{
58+
one = (one ^ n) & (~two);
59+
two = (two ^ n) & (~one);
60+
}
61+
return one;
62+
}
63+
};
64+
```
65+
#### Java
66+
```java
67+
class Solution {
68+
public int singleNumber(int[] nums) {
69+
int one=0, two=0;
70+
for(int n:nums)
71+
{
72+
one = (one ^ n) & (~two);
73+
two = (two ^ n) & (~one);
74+
}
75+
return one;
76+
}
77+
}
78+
```
79+
#### Python
80+
```python
81+
class Solution(object):
82+
def singleNumber(self, nums):
83+
one = two = 0
84+
for n in nums:
85+
one = (one ^ n) & (~two)
86+
two = (two ^ n) & (~one)
87+
return one
88+
```
4989

50-
![](../../Pictures/qrcode.jpg)
90+
![](../../Pictures/qrcode.jpg)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /