Skip to content

Commit

Permalink
Update 0137-Single-Number-II.md
Browse files Browse the repository at this point in the history
添加C++、Java、Python代码实现
  • Loading branch information
ztianming authored Jul 31, 2020
1 parent f43c086 commit 5c8e809
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion 0137-Single-Number-II/Article/0137-Single-Number-II.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,45 @@

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

### 代码实现
#### C++
```c++
class Solution {
public:
int singleNumber(vector<int>& nums) {
int one=0, two=0;
for(int n:nums)
{
one = (one ^ n) & (~two);
two = (two ^ n) & (~one);
}
return one;
}
};
```
#### Java
```java
class Solution {
public int singleNumber(int[] nums) {
int one=0, two=0;
for(int n:nums)
{
one = (one ^ n) & (~two);
two = (two ^ n) & (~one);
}
return one;
}
}
```
#### Python
```python
class Solution(object):
def singleNumber(self, nums):
one = two = 0
for n in nums:
one = (one ^ n) & (~two)
two = (two ^ n) & (~one)
return one
```

![](../../Pictures/qrcode.jpg)
![](../../Pictures/qrcode.jpg)

0 comments on commit 5c8e809

Please sign in to comment.