easy Java solution - readable


  • 0
    Y
    		int best = 0;
    		
    		for (int num : nums) {
    			if (num == 1) {
    				currentRun++;
    			} else {
    				currentRun = 0;
    			}
    			
    			if (currentRun > best)
    				best = currentRun;
    		}

Log in to reply
 

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