Go and slices trick


  • 0
    K

    Note that b uses the same backing array, so this does not contradict the condition

    func moveZeroes(nums []int)  {
        b := nums[:0]
    	lend := 0
    	for _, x := range nums {
    		if x!=0 {
    			b = append(b, x)	
    		} else {
    			lend++
    		}	
    	}
    	for lend > 0 {
    		b = append(b, 0)
    		lend--
    	}
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.