标签:temp rgb pre bsp ret ash 重复 turn length
示例 1:
输入: [2, 3, 1, 0, 2, 5, 3] 输出:2 或 3
class Solution1 { public int findRepeatNumber(int[] nums) { Set<Integer> set = new HashSet<Integer>(); int repeat = -1; for (int num : nums) { if (!set.add(num)) { repeat = num; break; } } return repeat; } }
class Solution2 { public int findRepeatNumber(int[] nums) { int temp; for (int i = 0; i < nums.length; i++) { while (nums[i] != i) { if (nums[i] == nums[nums[i]]) { return nums[i]; } temp = nums[i]; nums[i] = nums[temp]; nums[temp] = temp; } } return -1; } }
标签:temp rgb pre bsp ret ash 重复 turn length
原文地址:https://www.cnblogs.com/sixLiu/p/14158133.html