剑指Offer:数组中重复的数字(简单)
2020年8月7日
题目来源:力扣
解题
简单的想法,用数组记录出现次数,若不为0则说明重复,直接返回这个值
class Solution {
public int findRepeatNumber(int[] nums) {
int len=nums.length;
//新建一个长度为len的数组用来存放数字出现次数
int[] occ=new int[len];
for(int i=0;i<len;i++){
if(occ[nums[i]]==0){
occ[nums[i]]++;
}
else{
return nums[i];
}
}
return 0;
}
}
最后
以上就是天真御姐最近收集整理的关于LeetCode—剑指Offer:数组中重复的数字(临时数组)剑指Offer:数组中重复的数字(简单)的全部内容,更多相关LeetCode—剑指Offer:数组中重复内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复