[Java] Leetcode 26/80. Remove Duplicates from Sorted Array I/II [Two Pointers #3]

Поділитися
Вставка
  • Опубліковано 24 січ 2025

КОМЕНТАРІ • 17

  • @EricProgramming
    @EricProgramming  3 роки тому +7

    class SolutionNo1 {
    public int removeDuplicates(int[] nums) {
    int L = 0, R = 1;
    int N = nums.length;
    //L

    • @ketanmuttha1066
      @ketanmuttha1066 2 роки тому

      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?

  • @ingluissantana
    @ingluissantana 2 роки тому +3

    The 26 was easy but the 80 is still killing me. :P

    • @vishalupadhayay6391
      @vishalupadhayay6391 2 роки тому +1

      I was doing something very similar but then some test cases! uff!

  • @degea9
    @degea9 2 роки тому +1

    what tool did you use to draw on the web browser's screen ?

    • @EricProgramming
      @EricProgramming  2 роки тому +2

      It used to call web paint, but I think their interface has changed.

  • @pro_pranay
    @pro_pranay 7 місяців тому

    Hash set?

  • @luz8011
    @luz8011 2 роки тому

    wow, thank you so much!

  • @wonghuang1830
    @wonghuang1830 2 роки тому

    Thank you!

  • @Rob-J-BJJ
    @Rob-J-BJJ Рік тому +1

    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;
    }
    }

    • @Rob-J-BJJ
      @Rob-J-BJJ Рік тому

      how come i didnt do a base case and still passed all test cases?

  • @imram4u
    @imram4u 2 роки тому

    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

  • @chaitanyasharma6270
    @chaitanyasharma6270 2 роки тому

    public int removeDuplicates(int[] nums) {
    if(nums.length

  • @sulkhan5302
    @sulkhan5302 2 роки тому +5

    Honestly, I love watching your videos but this video really wasn't as clearly explained as the others (specifically the second problem).