File tree Expand file tree Collapse file tree 5 files changed +29
-8
lines changed
longest-consecutive-sequence Expand file tree Collapse file tree 5 files changed +29
-8
lines changed Original file line number Diff line number Diff line change 11import java .util .HashSet ;
22
3+ // link: https://leetcode.com/problems/contains-duplicate/description/
4+ // difficulty: Easy
35class Solution {
4- // return: does any value appear more than once in the array
5- // Time Complexity: O(n)
6- // Space Complexity: O(n)
6+ // Problem:
7+ // * return: does any value appear more than once in the array
8+ // Solution:
9+ // * Time Complexity: O(N)
10+ // * Space Complexity: O(N)
711 public boolean containsDuplicate (int [] nums ) {
12+ // Space Complexity: O(N)
813 HashSet <Integer > uniqNums = new HashSet <>();
914
15+ // Time Complexity: O(N)
1016 for (int num : nums ) {
1117 if (!uniqNums .add (num )) return true ;
1218 }
Original file line number Diff line number Diff line change 1+ // link: https://leetcode.com/problems/house-robber/description/
2+ // difficulty: Medium
13class Solution {
24 // Problem:
35 // * can't rob two adj houses in the same night
Original file line number Diff line number Diff line change 11import java .util .HashSet ;
22import java .util .Set ;
33
4+ // link: https://leetcode.com/problems/longest-consecutive-sequence/
5+ // difficulty: Medium
46class Solution {
57 // Problem:
68 // * nums is unsorted
Original file line number Diff line number Diff line change 11import java .util .*;
22
3+ // link: https://leetcode.com/problems/top-k-frequent-elements/description/
4+ // difficulty: Medium
5+
36// Time complexity: O(Nlogk)
47// Space complexity: O(N)
58class Solution1 {
Original file line number Diff line number Diff line change 11import java .util .HashMap ;
22import java .util .Map ;
33
4+ // link: https://leetcode.com/problems/two-sum/description/
5+ // difficulty: Easy
46class Solution {
5- // return: indices of two numbers that add up to `target`
7+ // Problem
68 // * exactly one solution
79 // * must use index only once
8-
9- // Time Complexity: O(n)
10- // Space Complexity: O(n)
10+ // * return: indices of two numbers that add up to `target`
11+ // Solution:
12+ // * Time Complexity: O(N)
13+ // * Space Complexity: O(N)
1114 public int [] twoSum (int [] nums , int target ) {
15+ // Space Complexity: O(N)
1216 Map <Integer , Integer > indexByNum = new HashMap <>();
1317
18+ // Time Complexity: O(N)
1419 for (int i = 0 ; i < nums .length ; i ++) {
1520 int numI = nums [i ];
1621 indexByNum .put (numI , i );
1722 }
1823
24+ // Time Complexity: O(N)
1925 for (int i = 0 ; i < nums .length ; i ++) {
2026 int numI = nums [i ];
2127 Integer compl = indexByNum .getOrDefault (target -numI , null );
22- if (compl != null && i != compl ) return new int [] {i , compl };
28+
29+ if (compl != null && i != compl )
30+ return new int [] {i , compl };
2331 }
2432
2533 return null ;
You can’t perform that action at this time.
0 commit comments