Contains Duplicate

Guys, I have recently started Data Structure 1. And the first question was :

Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

And my code was :

class Solution {
    public boolean containsDuplicate(int[] nums) {
        for (int i = 0; i < nums.length; i++){
            for (int j = 0; j < nums.length; j++){
                if (nums[i] == nums[j] && i != j){
                    return true;
                }
            }
        }
        return false;
    }
}

And as far as I know, my code is correct, but still I am having a Time Limit Exceeded error message.
Please help me.

Comments (1)