Skip to content

Commit f457030

Browse files
authored
feat(ml): 136.single-number.md (#407)
添加C、Java代码支持
1 parent 1c9c804 commit f457030

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

problems/136.single-number.md

+30-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Your algorithm should have a linear runtime complexity. Could you implement it w
4040

4141
## 代码
4242

43-
* 语言支持:JS,C++,Python
43+
* 语言支持:JS,C,C++,Java,Python
4444

4545
JavaScrip Code:
4646
```js
@@ -93,7 +93,20 @@ var singleNumber = function(nums) {
9393
return ret;
9494
};
9595
```
96-
C++:
96+
C Code:
97+
```C
98+
int singleNumber(int* nums, int numsSize){
99+
int res=0;
100+
for(int i=0;i<numsSize;i++)
101+
{
102+
res ^= nums[i];
103+
}
104+
105+
return res;
106+
}
107+
```
108+
109+
C++ Code:
97110
```C++
98111
class Solution {
99112
public:
@@ -113,6 +126,21 @@ public:
113126
};
114127
```
115128

129+
Java Code:
130+
```java
131+
class Solution {
132+
public int singleNumber(int[] nums) {
133+
int res = 0;
134+
for(int n:nums)
135+
{
136+
// 异或
137+
res ^= n;
138+
}
139+
return res;
140+
}
141+
}
142+
```
143+
116144
Python Code:
117145

118146
```python

0 commit comments

Comments
 (0)