samedi 13 novembre 2021

Why is it wrong to use if here,in golang,remove-duplicates-from-sorted-array

  1. I am a beginner and hope to get your help

  2. it is remove-duplicates-from-sorted-array

    func remove(nums []int)int{
     i,j:= 0,0
    
    
     //Why is it wrong to use if here?
     // if j< len(nums)
     for j < len(nums){
         if i==0 || nums[i-1]!= nums[j]{
             nums[i] = nums[j]
             i++
             j++
         }else{
             j++
         }
     }
     return i
    

    }

      func main(){
         nums := []int{1,2,2,3,5,5}
         result := remove(nums)
         fmt.Println(result)
       }
    
  3. please help me

Aucun commentaire:

Enregistrer un commentaire