File tree 2 files changed +51
-3
lines changed
2 files changed +51
-3
lines changed Original file line number Diff line number Diff line change 16
16
17
17
### Problems Solved
18
18
19
- | Total | 50 |
19
+ | Total | 51 |
20
20
| :---:| :---:|
21
21
22
22
#### Search By Topic
37
37
| Linked Lists | 5 |
38
38
| Math & Geometry | 4 |
39
39
| Priority Queue | 3 |
40
- | Sliding Window | 1 |
40
+ | Sliding Window | 2 |
41
41
| Stack | 2 |
42
42
| Tries | 0 |
43
43
| Two Pointers | 4 |
47
47
| Difficulty | Number |
48
48
| :---| ---:|
49
49
| Easy | 45 |
50
- | Medium | 5 |
50
+ | Medium | 6 |
51
51
| Hard | 0 |
52
52
53
53
## Milestones
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Problem: 3
3
+ * Name: Longest Substring Without Repeating Characters
4
+ * Difficulty: Medium
5
+ * Topic: Sliding Window
6
+ * Link: https://leetcode.com/problems/longest-substring-without-repeating-characters/
7
+ */
8
+
9
+ #include < bits/stdc++.h>
10
+ using namespace std ;
11
+
12
+ // Unordered Set
13
+ // Time Complexity: O(n)
14
+ // Space Complexity: O(n)
15
+ int lengthOfLongestSubstringUS (string s) {
16
+ int result = 0 ;
17
+ int left = 0 , right = 0 ;
18
+ unordered_set<char > chars;
19
+ while (right < s.size ()){
20
+ while (chars.count (s[right]) > 0 ) {
21
+ chars.erase (s[left]);
22
+ left++;
23
+ }
24
+ chars.insert (s[right]);
25
+ result = max (result, right - left + 1 );
26
+ right++;
27
+ }
28
+ return result;
29
+ }
30
+
31
+ // Bool Vector
32
+ // Time Complexity: O(n)
33
+ // Space Complexity: O(256)
34
+ int lengthOfLongestSubstringV (string s) {
35
+ int result = 0 ;
36
+ int left = 0 , right = 0 ;
37
+ vector<bool > chars (256 ,0 );
38
+ while (right < s.size ()){
39
+ while (chars[s[right]]) {
40
+ chars[s[left]] = 0 ;
41
+ left++;
42
+ }
43
+ chars[s[right]] = 1 ;
44
+ result = max (result, right - left + 1 );
45
+ right++;
46
+ }
47
+ return result;
48
+ }
You can’t perform that action at this time.
0 commit comments