File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
longest-substring-without-repeating-characters Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments