Skip to content

Latest commit

 

History

History
40 lines (34 loc) · 619 Bytes

remove_element.md

File metadata and controls

40 lines (34 loc) · 619 Bytes

Remove Element

tip: n(0)

base code

    func removeElement(nums []int, val int) int {
  left:=0
   for i :=0;i<len(nums);i++{
     if nums[i]!=val{
      
       nums[left]=nums[i]
       left++
     }
   }
   return  left
}

tow point code

tip: I should consider the possibility of utilizing 'for' next step . It seem quickly sort methods~

func removeElement(nums []int, val int) int {
  left:=0
  right:=len(nums)-1
   for left<=right{
      if nums[left]==val{
        nums[left]=nums[right]
           right--
      } else {
        left++
      }
   }
   return  left
}