class Solution { public int removeDuplicates(int[] nums) { int k = 1; int L = 0; int R = 1; int N = nums.length; while(R < N) { if (nums[L] == nums[R]) { R++;
} else if (nums[L] != nums[R]) { L++; int temp = nums[L]; nums[L] = nums[R]; // nums[R] = temp; k++;
Below is the python solution I tried to write as per the explanation. But it is throwing a wrong answer. can someone correct it pls class Solution: def removeDuplicates(self, nums: List[int]) -> int: n = len(nums) left =0 right = 1 count = 0 while(right < n): if (nums[left] != nums[right]): left +=1 nums[left] = nums[right] count = 0 elif (nums[left] == nums[right] and count < 1): count +=1 nums[left + 1] = nums[right] right +=1 return left + 1
class SolutionNo1 {
public int removeDuplicates(int[] nums) {
int L = 0, R = 1;
int N = nums.length;
//L
Thanks, Eric. I was trying to understand the reason to have this condition in your solution1
nums[++L] = nums[R]; ? why did you modify the array?
The 26 was easy but the 80 is still killing me. :P
I was doing something very similar but then some test cases! uff!
what tool did you use to draw on the web browser's screen ?
It used to call web paint, but I think their interface has changed.
Hash set?
wow, thank you so much!
Thank you!
class Solution {
public int removeDuplicates(int[] nums) {
int k = 1;
int L = 0;
int R = 1;
int N = nums.length;
while(R < N) {
if (nums[L] == nums[R]) {
R++;
}
else if (nums[L] != nums[R]) {
L++;
int temp = nums[L];
nums[L] = nums[R];
// nums[R] = temp;
k++;
}
}
return k;
}
}
how come i didnt do a base case and still passed all test cases?
Below is the python solution I tried to write as per the explanation. But it is throwing a wrong answer. can someone correct it pls
class Solution:
def removeDuplicates(self, nums: List[int]) -> int:
n = len(nums)
left =0
right = 1
count = 0
while(right < n):
if (nums[left] != nums[right]):
left +=1
nums[left] = nums[right]
count = 0
elif (nums[left] == nums[right] and count < 1):
count +=1
nums[left + 1] = nums[right]
right +=1
return left + 1
public int removeDuplicates(int[] nums) {
if(nums.length
Honestly, I love watching your videos but this video really wasn't as clearly explained as the others (specifically the second problem).
It could have been better! Agree.
Agree! Specially problem no 80