首页 > 其他 > 详细

编程杂烩

时间:2017-02-15 23:59:20      阅读:309      评论:0      收藏:0      [点我收藏+]
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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!