What is wrong with my code

  • 0

    This code pass 14/16. But I do not know what's wrong with my code.

    class Solution {
        bool containsDuplicate(vector<int>& nums) {
            for(int i = 0; i < nums.size(); i++) {
                for (int j = i + 1; j < nums.size(); j++) {
                    if (nums.at(i) == nums.at(j))
                        return true;
                return false;

  • 0

    First, maybe you should write your "return false" out of your first for-Loop.

    And, I think this question is executed in O(n) if you use Hash Table.

Log in to reply

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