Skip to content

Commit 4a45fbe

Browse files
committed
Add solution 137.
1 parent 6bdae39 commit 4a45fbe

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class Solution {
2+
3+
/**
4+
* @param Integer[] $nums
5+
* @return Integer
6+
*/
7+
function singleNumber($nums) {
8+
sort($nums);
9+
10+
$result = -1;
11+
$found = false;
12+
$i = 0;
13+
14+
while($found == false){
15+
$found = false;
16+
17+
if($i == count($nums) - 1){
18+
$result = $nums[$i];
19+
$found = true;
20+
break;
21+
}
22+
//if its next one, then we know three more of same number exist
23+
if($nums[$i] == $nums[$i+1]){
24+
$i+=3;
25+
continue;
26+
}
27+
else{
28+
//if not equal to the one next to it, we've found it.
29+
$result = $nums[$i];
30+
$found = true;
31+
break;
32+
}
33+
}
34+
return $result;
35+
}
36+
}

0 commit comments

Comments
 (0)