5 lines simple Java Solution


  • 13
    V

    public class Solution {

    public boolean containsDuplicate(int[] nums) {
        
        HashSet<Integer> flag = new HashSet<Integer>();
        
        for(int i : nums) {
            if(!flag.add(i)) {
                return true;
            }
        }
        return false;
    }
    

    }


  • 1
    A

    code to interface

    Set<Integer> flag = new HashSet<Integer>();

  • 0
    V

    Hmm...this is interesting. I am quite new to programming and I did not know about what the 'code to interface' practice before. Can you help me understand a bit more?


  • -10
    W

    The time : O(n^2);
    the space : O(n).
    So,you may improve it.


  • 3
    L

    Time is O(n) man. Do your homework.


Log in to reply
 

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