What's wrong with my code?


  • 0
    P
    class Solution {
    public:
        void moveZeroes(vector<int>& nums) {
            if(nums.size() == 0)
                return;
            int j = nums.size();
    	    for(int i=0; i<j; i++){
    		    if(nums[i] == 0){
    			    for(int k=i; k<j; k++){
    			        if(nums[k+1] != NULL){
    				    int temp = nums[k];
    				    nums[k] = nums[k+1];
    				    nums[k+1] = temp;
    			        }
    			    }
    			j--;
    	        }
            }
        }
    };
    

    If I do a custom testcase with [0] it works but when I submit it I'm getting [32606] as the output for [0].


Log in to reply
 

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