class Solution { public void moveZeroes(int[] nums) { int result=0 ; for(int i =0 ;i < nums.length;i ++){ if(nums[i]!= 0){ nums[result++] = nums[i]; } } while (result < nums.length){ nums[result++] = 0 ; } } }
二、第一个错误版本
package my; public class FirstBadVersionSolution { public int firstBadVersion(int n){ int low = 1; int high = n; while(low < high){ int middle = low + (high - low)/2 ; if(isBadVersion(middle)){ high = middle; }else{ low = middle +1; } } return low; } //随便实现一个 boolean isBadVersion(int version){ if(version == 4){ return true; }else{ return false; } } }
三、Nim Game
class Solution { public boolean canWinNim(int n) { if(n % 4 ==0){ return false ; }else{ return true ; } } }