We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 35db71c commit 4554647Copy full SHA for 4554647
longest-substring-without-repeating-characters/TonyKim9401.java
@@ -0,0 +1,25 @@
1
+// TC: O(n^2)
2
+// -> all elements can be retrived multiple times in the worst case
3
+// SC: O(1)
4
+// -> since declare, no more increase or decrease
5
+class Solution {
6
+ public int lengthOfLongestSubstring(String s) {
7
+ int max = 0;
8
+ int count = 0;
9
+ boolean[] checkList = new boolean[128];
10
+
11
+ for (int i = 0; i < s.length(); i++) {
12
+ int idx = s.charAt(i);
13
+ if (checkList[idx]) {
14
+ max = Math.max(max, count);
15
+ i -= count;
16
+ count = 0;
17
+ checkList = new boolean[128];
18
+ } else {
19
+ count += 1;
20
+ checkList[idx] = true;
21
+ }
22
23
+ return max = Math.max(max, count);
24
25
+}
0 commit comments