Skip to content

Commit ed42654

Browse files
committed
Add solution 26.
1 parent 5825991 commit ed42654

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution {
2+
3+
/**
4+
* @param Integer[] $nums
5+
* @return Integer
6+
*/
7+
function removeDuplicates(&$nums) {
8+
if (count($nums) < 2)
9+
return count($nums);
10+
11+
$j = 0;
12+
$i = 1;
13+
14+
while ($i < count($nums)) {
15+
if ($nums[$i] == $nums[$j]) {
16+
$i++;
17+
} else {
18+
$j++;
19+
$nums[$j] = $nums[$i];
20+
$i++;
21+
}
22+
}
23+
24+
return $j + 1;
25+
}
26+
}

0 commit comments

Comments
 (0)