Skip to content

Commit 3276ff8

Browse files
authored
Merge pull request #2228 from se6816/main
[se6816] WEEK 07 solutions
2 parents 98c8960 + ab500f9 commit 3276ff8

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

reverse-linked-list/se6816.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
리스트의 길이 -> N
3+
시간 복잡도 : O(N)
4+
공간 복잡도 : O(1)
5+
*/
6+
class Solution {
7+
public ListNode reverseList(ListNode head) {
8+
return createReverseHead(head);
9+
}
10+
private ListNode createReverseHead(ListNode head) {
11+
ListNode resultHead = null;
12+
13+
while (head != null) {
14+
ListNode next = head.next;
15+
head.next = resultHead;
16+
resultHead = head;
17+
head = next;
18+
}
19+
20+
return resultHead;
21+
}
22+
}

0 commit comments

Comments
 (0)