We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6bdae39 commit 4a45fbeCopy full SHA for 4a45fbe
src/Algorithms/0137.single-number-ii/single-number-ii.php
@@ -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
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
30
31
32
33
34
+ return $result;
35
36
+}
0 commit comments