File tree 1 file changed +41
-1
lines changed
0137-Single-Number-II/Article
1 file changed +41
-1
lines changed Original file line number Diff line number Diff line change 46
46
47
47
![ ] ( ../Animation/137.gif )
48
48
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
+ ```
49
89
50
- ![ ] ( ../../Pictures/qrcode.jpg )
90
+ ![ ] ( ../../Pictures/qrcode.jpg )
You can’t perform that action at this time.
0 commit comments