Skip to content

Commit 5c8e809

Browse files
authored
Update 0137-Single-Number-II.md
添加C++、Java、Python代码实现
1 parent f43c086 commit 5c8e809

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

+41-1
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)