Java Solution, simple double-nested for loop


  • -3
    R
    static boolean containsDuplicate(int[] nums) {
            boolean result = false;
            int len = nums.length;
            for (int i = 0; i < len; i++){
                for (int j = 0; j < len; j++){
                    if (i == j){
                        continue;
                    }
                    if (nums[i] == nums[j]){
                        result = true;
                    }
                }
            }
            return result;
        }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.