leetcode 217. Contains Duplicate
Given an array of integers, find if the array contains any duplicates.Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
Example 1:
Input:
Output: true
Example 2:
Input:
Output: false
Example 3:
Input:
Output: true
class Solution {
public boolean containsDuplicate(int[] nums) {
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
for(int i : nums){
if(i > max) max = i;
if(i < min) min = i;
}
boolean[] re = new boolean;
for(int i : nums){
if(re) return true;
re = true;
}
return false;
}
}
页:
[1]