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 7b59476 commit 1ff586cCopy full SHA for 1ff586c
1 file changed
longest-substring-without-repeating-characters/se6816.java
@@ -0,0 +1,37 @@
1
+/**
2
+ 투포인터를 이용한 방식
3
+ 문자열 s의 길이 -> N
4
+ 시간 복잡도 : O(N)
5
+ 공간 복잡도 : O(N)
6
+ */
7
+
8
+class Solution {
9
+ public int lengthOfLongestSubstring(String s) {
10
+ if(s.length()==0){
11
+ return 0;
12
+ }
13
+ Set<Character> set =new HashSet<>();
14
+ int start=0;
15
+ int end=0;
16
+ int maxSize=0;
17
+ int len = s.length();
18
+ while(start < len){
19
20
21
+ for(int i=end; i < len;i++){
22
+ char ch = s.charAt(i);
23
+ if(set.contains(ch)){
24
+ end = i;
25
+ break;
26
27
+ set.add(ch);
28
29
30
+ maxSize = Math.max(maxSize, set.size());
31
+ set.remove(s.charAt(start));
32
+ start++;
33
34
35
+ return maxSize;
36
37
+}
0 commit comments