From 8c4af7c6c1cf63d4cae33b606479ed77a13d2fe3 Mon Sep 17 00:00:00 2001 From: eunhwa99 Date: Fri, 10 Jan 2025 20:35:47 +0900 Subject: [PATCH 01/14] valid parentheses --- leetcode-study | 1 + leetcode-study-1 | 1 + top-k-frequent-elements/leetcode-study | 1 + valid-parentheses/eunhwa99.java | 31 ++++++++++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 160000 leetcode-study create mode 160000 leetcode-study-1 create mode 160000 top-k-frequent-elements/leetcode-study create mode 100644 valid-parentheses/eunhwa99.java diff --git a/leetcode-study b/leetcode-study new file mode 160000 index 000000000..77bcf764a --- /dev/null +++ b/leetcode-study @@ -0,0 +1 @@ +Subproject commit 77bcf764aa743b71c5d762c3d3af26a4775a280c diff --git a/leetcode-study-1 b/leetcode-study-1 new file mode 160000 index 000000000..58e2901af --- /dev/null +++ b/leetcode-study-1 @@ -0,0 +1 @@ +Subproject commit 58e2901afafa568cb0f15d5e002c23444e22cf31 diff --git a/top-k-frequent-elements/leetcode-study b/top-k-frequent-elements/leetcode-study new file mode 160000 index 000000000..32ed2baa8 --- /dev/null +++ b/top-k-frequent-elements/leetcode-study @@ -0,0 +1 @@ +Subproject commit 32ed2baa8e51b39625f99ea72a780c6edca6e9ee diff --git a/valid-parentheses/eunhwa99.java b/valid-parentheses/eunhwa99.java new file mode 100644 index 000000000..c980cca30 --- /dev/null +++ b/valid-parentheses/eunhwa99.java @@ -0,0 +1,31 @@ +import java.util.HashMap; +import java.util.Map; +import java.util.Stack; + +class Solution { + public boolean isValid(String s) { + char[] array = s.toCharArray(); + Map pMap = new HashMap<>(); + pMap.put(')','('); + pMap.put('}','{'); + pMap.put(']','['); + + Stack stack = new Stack<>(); + for(char parenthes: array){ + if((parenthes == ')') || (parenthes=='}') || (parenthes==']')){ + if(stack.isEmpty()) return false; // invalid + + char myPair = pMap.get(parenthes); + if(stack.peek()==myPair){ + stack.pop(); + } + else return false; + } + else{ + stack.push(parenthes); + } + } + + return stack.empty(); + } +} \ No newline at end of file From 02f4602039c2260a415b6a16077585b7b4348ff2 Mon Sep 17 00:00:00 2001 From: eunhwa99 Date: Fri, 10 Jan 2025 22:04:58 +0900 Subject: [PATCH 02/14] Add comment --- valid-parentheses/eunhwa99.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/valid-parentheses/eunhwa99.java b/valid-parentheses/eunhwa99.java index c980cca30..96274dc72 100644 --- a/valid-parentheses/eunhwa99.java +++ b/valid-parentheses/eunhwa99.java @@ -2,6 +2,11 @@ import java.util.Map; import java.util.Stack; +// 열린 괄호일 경우. 스택에 푸쉬 +// 닫힌 괄호일 경우, 스택의 top 부분이 같은 종류의 열린 괄호이면 pop, 다른 종류 열린 괄호이면 invalid한 문자열 + +// 시간 복잡도: 스택의 크기 = 문자열의 크기 O(N) +// 공간 복잡도: 스택의 크기 = O(N) class Solution { public boolean isValid(String s) { char[] array = s.toCharArray(); @@ -28,4 +33,4 @@ public boolean isValid(String s) { return stack.empty(); } -} \ No newline at end of file +} From 0a4c99a459d746268d237dea8d74933c754adf35 Mon Sep 17 00:00:00 2001 From: eunhwa99 Date: Fri, 10 Jan 2025 22:51:27 +0900 Subject: [PATCH 03/14] container with most water --- container-with-most-water/eunhwa99.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 container-with-most-water/eunhwa99.java diff --git a/container-with-most-water/eunhwa99.java b/container-with-most-water/eunhwa99.java new file mode 100644 index 000000000..2dd852231 --- /dev/null +++ b/container-with-most-water/eunhwa99.java @@ -0,0 +1,22 @@ +// two pointer + +// 시간 복잡도: O(nlogn) - 투 포인터 +// 공간 복잡도: O(n) - height 배열 크기 + +class Solution { + public int maxArea(int[] height) { + int left=0; + int right = height.length-1; + + int maxContainer = 0; + while(left Date: Sat, 11 Jan 2025 10:29:38 +0900 Subject: [PATCH 04/14] longest increasing subsequence --- longest-increasing-subsequence/eunhwa99.java | 55 ++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 longest-increasing-subsequence/eunhwa99.java diff --git a/longest-increasing-subsequence/eunhwa99.java b/longest-increasing-subsequence/eunhwa99.java new file mode 100644 index 000000000..7cd83087c --- /dev/null +++ b/longest-increasing-subsequence/eunhwa99.java @@ -0,0 +1,55 @@ +class Solution { + + // lenArr[i] : i를 마지막 원소로 하는 최장 부분 수열 길이 + // 시간 복잡도: O(N*N) -> 이중 반복문 + // 공간 복잡도: O(N) -> 배열 크기 + public int lengthOfLIS(int[] nums) { + int[] lenArr = new int[nums.length]; + for(int i=0;inums[j]){ + lenArr[i] = Math.max(lenArr[j] +1, lenArr[i]); + // j번째 숫자를 수열에 포함시키거나 포함시키지 않음 -> 두 개 비교해서 Max 값 찾는다. + } + } + } + + int result = 0; + for(int i=0;i BinarySearch 로도 가능하다...! +// 시간 복잡도 : O(NlogN) +// 공간 복잡도: O(N) +class Solution { + public int lengthOfLIS(int[] nums) { + int[] list = new int[nums.length]; + int j = -1; + for(int i=0;i 따라서 left = mid + 1로 범위를 좁힌다. + else right = mid; + } + list[left] = nums[i]; + + } + } + + return j + 1; + } + +} From 020c6198c751ab242ea56c1e5fa64e5d9fe727db Mon Sep 17 00:00:00 2001 From: eunhwa99 Date: Sat, 11 Jan 2025 13:16:44 +0900 Subject: [PATCH 05/14] spiral matrix --- spiral-matrix/eunhwa99.java | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 spiral-matrix/eunhwa99.java diff --git a/spiral-matrix/eunhwa99.java b/spiral-matrix/eunhwa99.java new file mode 100644 index 000000000..3304d4c01 --- /dev/null +++ b/spiral-matrix/eunhwa99.java @@ -0,0 +1,47 @@ +// 시간 복잡도: O(N*N) +// 공간 복잡도: O(N*N) + +// 이동하는 방향을 바꾸는 조건 (아래 중 하나 만족) +// 1. 다음에 갈 곳이 이미 방문한 곳 +// 2. 다음에 갈 곳이 배열 범위를 벗어난 곳 +class Solution { + public List spiralOrder(int[][] matrix) { + int row = matrix.length; + int col = matrix[0].length; + boolean[][] visited = new boolean[row][col]; + + // right, down, left, up + int[] dirY = new int[]{1,0,-1,0}; // 열 방향 + int[] dirX = new int[]{0,1,0,-1}; // 행 방향 + int dirPointer = 0; + + List result = new ArrayList<>(); + + int x = 0, y = 0; + int cnt = 0; int total = row*col; + while(cnt < total){ + + result.add(matrix[x][y]); + visited[x][y]=true; + ++cnt; + // 다음 좌표로 이동 + int nextX = x + dirX[dirPointer]; + int nextY = y + dirY[dirPointer]; + + // 경계 조건 체크 및 방향 전환 + if (nextX < 0 || nextX >= row || nextY < 0 || nextY >= col || visited[nextX][nextY]) { + // 현재 방향에서 벗어나면 방향을 변경 + dirPointer = (dirPointer + 1) % 4; + nextX = x + dirX[dirPointer]; + nextY = y + dirY[dirPointer]; + } + + // 좌표 업데이트 + x = nextX; + y = nextY; + } + + + return result; + } +} From 65c2173105b054a9e3e2f8a954b4d973d71ef0e7 Mon Sep 17 00:00:00 2001 From: eunhwa99 Date: Sat, 11 Jan 2025 22:37:24 +0900 Subject: [PATCH 06/14] design add and search words data structure --- .../eunhwa99.java | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 design-add-and-search-words-data-structure/eunhwa99.java diff --git a/design-add-and-search-words-data-structure/eunhwa99.java b/design-add-and-search-words-data-structure/eunhwa99.java new file mode 100644 index 000000000..43b402f85 --- /dev/null +++ b/design-add-and-search-words-data-structure/eunhwa99.java @@ -0,0 +1,109 @@ +import java.util.HashSet; +import java.util.Set; + +// 풀이 1 : 단순 반복문 +// 시간 복잡도: N(단어 길이), M(단어 개수) -> O(N*M) +// 공간 복잡도: O(M) +class WordDictionary { + + Set wordSet; + public WordDictionary() { + wordSet = new HashSet<>(); + } + + public void addWord(String word) { + wordSet.add(word); + } + + public boolean search(String word) { + if(word.contains(".")){ + char[] wordArr = word.toCharArray(); + boolean found = false; + for(String w: wordSet){ + if(word.length()!=w.length()) continue; + + char[] charArr = w.toCharArray(); + for(int i=0;i O(26^N * N) +// 공간 복잡도: O(M) +class TrieNode { + TrieNode[] child; + boolean isEnd; // flag if the node is end. + + public TrieNode() { + child = new TrieNode[26]; // 알파벳 개수 + isEnd = false; + } +} + +class WordDictionary { + TrieNode root; + + public WordDictionary() { + root = new TrieNode(); // trie 루트 생성 + } + + public void addWord(String word) { + TrieNode cur = root; + for (char w : word.toCharArray()) { + if (cur.child[w - 'a'] == null) { + cur.child[w - 'a'] = new TrieNode(); // 자식 생성 + } + cur = cur.child[w - 'a']; + } + cur.isEnd = true; + } + + public boolean search(String word) { + return dfs(root, word, 0); // dfs 호출 시, index도 전달 + } + + // dfs를 수행하며, 현재 인덱스까지 탐색한 상태에서 단어를 검색 + private boolean dfs(TrieNode cur, String word, int index) { + // 단어 끝에 도달했으면, 현재 노드가 끝을 나타내는지 확인 + if (index == word.length()) { + return cur.isEnd; + } + + char c = word.charAt(index); + + // '.' 이면 모든 자식 노드에 대해 재귀적으로 탐색 + if (c == '.') { + for (TrieNode child : cur.child) { + if (child != null && dfs(child, word, index + 1)) { + return true; + } + } + return false; + } else { + // '.'이 아닌 경우, 해당 문자에 해당하는 자식으로 계속 내려감 + if (cur.child[c - 'a'] == null) { + return false; + } + return dfs(cur.child[c - 'a'], word, index + 1); + } + } +} + From ebd20544a4b27ae75d324e0a3175348620299a91 Mon Sep 17 00:00:00 2001 From: eunhwa99 Date: Sat, 11 Jan 2025 22:37:51 +0900 Subject: [PATCH 07/14] =?UTF-8?q?=EB=B3=B5=EC=9E=A1=EB=8F=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- design-add-and-search-words-data-structure/eunhwa99.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/design-add-and-search-words-data-structure/eunhwa99.java b/design-add-and-search-words-data-structure/eunhwa99.java index 43b402f85..b3b79d00c 100644 --- a/design-add-and-search-words-data-structure/eunhwa99.java +++ b/design-add-and-search-words-data-structure/eunhwa99.java @@ -47,7 +47,7 @@ public boolean search(String word) { // 풀이2: trie // 시간 복잡도: N(단어 길이) -> O(26^N * N) -// 공간 복잡도: O(M) +// 공간 복잡도: O(N * M) - M(단어 개수) class TrieNode { TrieNode[] child; boolean isEnd; // flag if the node is end. From 6a3ef600745c879ac9640ffcf694e956c942519c Mon Sep 17 00:00:00 2001 From: eunhwa99 Date: Tue, 14 Jan 2025 20:29:21 +0900 Subject: [PATCH 08/14] Remove unnecessary folder --- leetcode-study | 1 - leetcode-study-1 | 1 - top-k-frequent-elements/leetcode-study | 1 - 3 files changed, 3 deletions(-) delete mode 160000 leetcode-study delete mode 160000 leetcode-study-1 delete mode 160000 top-k-frequent-elements/leetcode-study diff --git a/leetcode-study b/leetcode-study deleted file mode 160000 index 77bcf764a..000000000 --- a/leetcode-study +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 77bcf764aa743b71c5d762c3d3af26a4775a280c diff --git a/leetcode-study-1 b/leetcode-study-1 deleted file mode 160000 index 58e2901af..000000000 --- a/leetcode-study-1 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 58e2901afafa568cb0f15d5e002c23444e22cf31 diff --git a/top-k-frequent-elements/leetcode-study b/top-k-frequent-elements/leetcode-study deleted file mode 160000 index 32ed2baa8..000000000 --- a/top-k-frequent-elements/leetcode-study +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 32ed2baa8e51b39625f99ea72a780c6edca6e9ee From 8ed7e2eea080bdb16e72b3fe498c0898ecb34f06 Mon Sep 17 00:00:00 2001 From: eunhwa99 Date: Tue, 14 Jan 2025 20:30:30 +0900 Subject: [PATCH 09/14] fix comment for two-pointer --- container-with-most-water/eunhwa99.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-with-most-water/eunhwa99.java b/container-with-most-water/eunhwa99.java index 2dd852231..0a9aecd27 100644 --- a/container-with-most-water/eunhwa99.java +++ b/container-with-most-water/eunhwa99.java @@ -1,6 +1,6 @@ // two pointer -// 시간 복잡도: O(nlogn) - 투 포인터 +// 시간 복잡도: O(n) - 투 포인터 // 공간 복잡도: O(n) - height 배열 크기 class Solution { From 047a415438a8373121413e6a52fd11bdca53efbf Mon Sep 17 00:00:00 2001 From: eunhwa99 Date: Tue, 14 Jan 2025 20:34:42 +0900 Subject: [PATCH 10/14] add line --- container-with-most-water/eunhwa99.java | 1 + design-add-and-search-words-data-structure/eunhwa99.java | 1 + longest-increasing-subsequence/eunhwa99.java | 1 + spiral-matrix/eunhwa99.java | 1 + valid-parentheses/eunhwa99.java | 1 + 5 files changed, 5 insertions(+) diff --git a/container-with-most-water/eunhwa99.java b/container-with-most-water/eunhwa99.java index 0a9aecd27..2557f0c44 100644 --- a/container-with-most-water/eunhwa99.java +++ b/container-with-most-water/eunhwa99.java @@ -20,3 +20,4 @@ public int maxArea(int[] height) { return maxContainer; } } + diff --git a/design-add-and-search-words-data-structure/eunhwa99.java b/design-add-and-search-words-data-structure/eunhwa99.java index b3b79d00c..36560a398 100644 --- a/design-add-and-search-words-data-structure/eunhwa99.java +++ b/design-add-and-search-words-data-structure/eunhwa99.java @@ -107,3 +107,4 @@ private boolean dfs(TrieNode cur, String word, int index) { } } + diff --git a/longest-increasing-subsequence/eunhwa99.java b/longest-increasing-subsequence/eunhwa99.java index 7cd83087c..d8cddfab3 100644 --- a/longest-increasing-subsequence/eunhwa99.java +++ b/longest-increasing-subsequence/eunhwa99.java @@ -53,3 +53,4 @@ public int lengthOfLIS(int[] nums) { } } + diff --git a/spiral-matrix/eunhwa99.java b/spiral-matrix/eunhwa99.java index 3304d4c01..fe7eb8284 100644 --- a/spiral-matrix/eunhwa99.java +++ b/spiral-matrix/eunhwa99.java @@ -45,3 +45,4 @@ public List spiralOrder(int[][] matrix) { return result; } } + diff --git a/valid-parentheses/eunhwa99.java b/valid-parentheses/eunhwa99.java index 96274dc72..91197d431 100644 --- a/valid-parentheses/eunhwa99.java +++ b/valid-parentheses/eunhwa99.java @@ -34,3 +34,4 @@ public boolean isValid(String s) { return stack.empty(); } } + From fa625bd132b73b4e2a36ac6071e663547ffb6e0a Mon Sep 17 00:00:00 2001 From: eunhwa99 Date: Wed, 15 Jan 2025 22:28:57 +0900 Subject: [PATCH 11/14] reverse linked list --- leetcode-study | 1 + leetcode-study-1 | 1 + reverse-linked-list/eunhwa99.java | 29 ++++++++++++++++++++++++++ top-k-frequent-elements/leetcode-study | 1 + 4 files changed, 32 insertions(+) create mode 160000 leetcode-study create mode 160000 leetcode-study-1 create mode 100644 reverse-linked-list/eunhwa99.java create mode 160000 top-k-frequent-elements/leetcode-study diff --git a/leetcode-study b/leetcode-study new file mode 160000 index 000000000..047a41543 --- /dev/null +++ b/leetcode-study @@ -0,0 +1 @@ +Subproject commit 047a415438a8373121413e6a52fd11bdca53efbf diff --git a/leetcode-study-1 b/leetcode-study-1 new file mode 160000 index 000000000..58e2901af --- /dev/null +++ b/leetcode-study-1 @@ -0,0 +1 @@ +Subproject commit 58e2901afafa568cb0f15d5e002c23444e22cf31 diff --git a/reverse-linked-list/eunhwa99.java b/reverse-linked-list/eunhwa99.java new file mode 100644 index 000000000..752a70313 --- /dev/null +++ b/reverse-linked-list/eunhwa99.java @@ -0,0 +1,29 @@ +/** + * Definition for singly-linked list. + * public class ListNode { + * int val; + * ListNode next; + * ListNode() {} + * ListNode(int val) { this.val = val; } + * ListNode(int val, ListNode next) { this.val = val; this.next = next; } + * } + */ + + // 시간 복잡도: O(N) + // 공간복잡도: O(N) +class Solution { + public ListNode reverseList(ListNode head) { + if(head==null) return head; + + ListNode pointer = new ListNode(head.val); + + ListNode tempPointer; + while(head.next!=null){ + tempPointer = new ListNode(head.next.val, pointer); + pointer = tempPointer; + head = head.next; + } + } + return pointer; +} + diff --git a/top-k-frequent-elements/leetcode-study b/top-k-frequent-elements/leetcode-study new file mode 160000 index 000000000..32ed2baa8 --- /dev/null +++ b/top-k-frequent-elements/leetcode-study @@ -0,0 +1 @@ +Subproject commit 32ed2baa8e51b39625f99ea72a780c6edca6e9ee From c68a5b04ff3f891c0d5430f96fd8d19ed8971c6b Mon Sep 17 00:00:00 2001 From: eunhwa99 Date: Sat, 18 Jan 2025 13:38:23 +0900 Subject: [PATCH 12/14] longest subsring without repeating characters --- .../eunhwa99.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 longest-substring-without-repeating-characters/eunhwa99.java diff --git a/longest-substring-without-repeating-characters/eunhwa99.java b/longest-substring-without-repeating-characters/eunhwa99.java new file mode 100644 index 000000000..264a0cfcb --- /dev/null +++ b/longest-substring-without-repeating-characters/eunhwa99.java @@ -0,0 +1,25 @@ +class Solution { + // 시간 복잡도: O(N) + // 공간 복잡도: O(N) + public int lengthOfLongestSubstring(String s) { + Map position = new HashMap<>(); + int start = 0; // substring의 시작점 + int maxLength = 0; + + for (int idx = 0; idx < s.length(); idx++) { + char currentChar = s.charAt(idx); + + // 같은 문자가 이미 map 에 있고, 그 문자가 현재 substring에 포함된 문자인지 확인 + if (position.containsKey(currentChar) && position.get(currentChar) >= start) { + start = position.get(currentChar) + 1; + // 같은 문자가 포함되지 않게 substring의 시작을 옮긴다. + } + + maxLength = Math.max(maxLength, idx - start + 1); + + position.put(currentChar, idx); + } + + return maxLength; + } + } From 61e5d3682a32047e43625210511b2e9617b900f4 Mon Sep 17 00:00:00 2001 From: eunhwa99 Date: Sat, 18 Jan 2025 13:43:35 +0900 Subject: [PATCH 13/14] Revert "longest subsring without repeating characters" This reverts commit c68a5b04ff3f891c0d5430f96fd8d19ed8971c6b. --- .../eunhwa99.java | 25 ------------------- 1 file changed, 25 deletions(-) delete mode 100644 longest-substring-without-repeating-characters/eunhwa99.java diff --git a/longest-substring-without-repeating-characters/eunhwa99.java b/longest-substring-without-repeating-characters/eunhwa99.java deleted file mode 100644 index 264a0cfcb..000000000 --- a/longest-substring-without-repeating-characters/eunhwa99.java +++ /dev/null @@ -1,25 +0,0 @@ -class Solution { - // 시간 복잡도: O(N) - // 공간 복잡도: O(N) - public int lengthOfLongestSubstring(String s) { - Map position = new HashMap<>(); - int start = 0; // substring의 시작점 - int maxLength = 0; - - for (int idx = 0; idx < s.length(); idx++) { - char currentChar = s.charAt(idx); - - // 같은 문자가 이미 map 에 있고, 그 문자가 현재 substring에 포함된 문자인지 확인 - if (position.containsKey(currentChar) && position.get(currentChar) >= start) { - start = position.get(currentChar) + 1; - // 같은 문자가 포함되지 않게 substring의 시작을 옮긴다. - } - - maxLength = Math.max(maxLength, idx - start + 1); - - position.put(currentChar, idx); - } - - return maxLength; - } - } From a26f8ee52c199fee80ce5e2d295217b3f7a7c71c Mon Sep 17 00:00:00 2001 From: eunhwa99 Date: Sat, 18 Jan 2025 13:43:45 +0900 Subject: [PATCH 14/14] Revert "reverse linked list" This reverts commit fa625bd132b73b4e2a36ac6071e663547ffb6e0a. --- leetcode-study | 1 - leetcode-study-1 | 1 - reverse-linked-list/eunhwa99.java | 29 -------------------------- top-k-frequent-elements/leetcode-study | 1 - 4 files changed, 32 deletions(-) delete mode 160000 leetcode-study delete mode 160000 leetcode-study-1 delete mode 100644 reverse-linked-list/eunhwa99.java delete mode 160000 top-k-frequent-elements/leetcode-study diff --git a/leetcode-study b/leetcode-study deleted file mode 160000 index 047a41543..000000000 --- a/leetcode-study +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 047a415438a8373121413e6a52fd11bdca53efbf diff --git a/leetcode-study-1 b/leetcode-study-1 deleted file mode 160000 index 58e2901af..000000000 --- a/leetcode-study-1 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 58e2901afafa568cb0f15d5e002c23444e22cf31 diff --git a/reverse-linked-list/eunhwa99.java b/reverse-linked-list/eunhwa99.java deleted file mode 100644 index 752a70313..000000000 --- a/reverse-linked-list/eunhwa99.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode() {} - * ListNode(int val) { this.val = val; } - * ListNode(int val, ListNode next) { this.val = val; this.next = next; } - * } - */ - - // 시간 복잡도: O(N) - // 공간복잡도: O(N) -class Solution { - public ListNode reverseList(ListNode head) { - if(head==null) return head; - - ListNode pointer = new ListNode(head.val); - - ListNode tempPointer; - while(head.next!=null){ - tempPointer = new ListNode(head.next.val, pointer); - pointer = tempPointer; - head = head.next; - } - } - return pointer; -} - diff --git a/top-k-frequent-elements/leetcode-study b/top-k-frequent-elements/leetcode-study deleted file mode 160000 index 32ed2baa8..000000000 --- a/top-k-frequent-elements/leetcode-study +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 32ed2baa8e51b39625f99ea72a780c6edca6e9ee