public int sumArray(int[] nums, int start, int end) { int i=0; int sum=0; for(i=start;i<=end;i++){ sum+=nums[i]; } return sum; } public boolean canBalance(int[] nums) { int i=0; int firstHalfSum; int secondHalfSum; while(i<nums.length){ firstHalfSum=sumArray(nums, 0 , i); secondHalfSum=sumArray(nums , i+1, nums.length-1); if(firstHalfSum==secondHalfSum) return true; i++; } return false; }
public Map<String, Integer> word0(String[] strings) { int i=0; Map<String, Integer> wordMap = new HashMap<String, Integer>(); while(i<strings.length){ if( ! wordMap.containsKey(strings[i]) ) wordMap.put(strings[i], 0); i++; } return wordMap; }
原文:http://www.cnblogs.com/youge-OneSQL/p/6403711.html