Skip to content

Commit 16fb71d

Browse files
committed
[Week7](gmlwls96) Longest Substring Without Repeating Characters
1 parent 97099af commit 16fb71d

File tree

1 file changed

+17
-0
lines changed
  • longest-substring-without-repeating-characters

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
// 시간 : O(n) 공간 : O(n)
3+
fun lengthOfLongestSubstring(s: String): Int {
4+
var max = 0
5+
val subStr = StringBuffer()
6+
s.forEach { // s를 조회하면서 글자를 subStr에 담는다.
7+
if (subStr.contains(it)) { // 단, 겹치는 글자가 있을경우 subStr의 len을 기록하고, 초기화 한다.
8+
max = max(max, subStr.length)
9+
subStr.delete(0, subStr.length)
10+
}
11+
subStr.append(it)
12+
}
13+
max = max(max, subStr.length)
14+
println(subStr)
15+
return max
16+
}
17+
}

0 commit comments

Comments
 (0)