File tree Expand file tree Collapse file tree 4 files changed +31
-0
lines changed
design-add-and-search-words-data-structure
longest-increasing-subsequence Expand file tree Collapse file tree 4 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -9,11 +9,22 @@ class TrieNode {
99}
1010
1111class WordDictionary {
12+ /**
13+ * space-complexity : O(N * L) (w.c)
14+ * - N : 단어 수, L : 평균 길이
15+ * - 단어 하나 추가 시 최대 L개의 TrieNode 생성
16+ * - (w.c) 모든 단어가 중복 없이 추가되면 (N*L)개의 노드 필요
17+ */
1218 TrieNode root ;
1319 public WordDictionary () {
1420 this .root = new TrieNode ();
1521 }
1622
23+ /**
24+ * addWord() Time-complexity : O(L)
25+ * - 각 문자마다 TrieNode를 따라 내려가며 필요한 경우 새 노드 생성
26+ * - 한 단어당 최대 L개의 노드 생성 및 접근
27+ */
1728 public void addWord (String word ) {
1829
1930 TrieNode curr = root ;
@@ -26,6 +37,14 @@ public void addWord(String word) {
2637 curr .word = true ;
2738 }
2839
40+ /**
41+ * search() Time-complexity :
42+ * - '.'가 없는 경우 : O(L)
43+ * -> 일반적인 문자는 한 경로만 탐색
44+ * - '.'가 있는 경우 : O(26^L) (w.c)
45+ * -> 현재 노드의 모든 자식에 대해 DFS 수행
46+ *
47+ */
2948 public boolean search (String word ) {
3049 return dfs (word , 0 , root );
3150 }
Original file line number Diff line number Diff line change 11import java .util .*;
22class Solution {
3+ /**
4+ * time-complexity : O(n^2)
5+ * space-complexity : O(n)
6+ */
37 public int lengthOfLIS (int [] nums ) {
48
59 int [] dp = new int [nums .length ];
Original file line number Diff line number Diff line change 11import java .util .*;
22class Solution {
3+ /**
4+ * time-complexity : O(n * m)
5+ * space-complexity : O(1) (excluding the output List)
6+ */
37 public List <Integer > spiralOrder (int [][] matrix ) {
48
59 List <Integer > result = new ArrayList <>();
Original file line number Diff line number Diff line change 11import java .util .*;
22class Solution {
3+ /**
4+ * time-complexity : O(n)
5+ * space-complexity : O(n)
6+ */
37 public boolean isValid (String s ) {
48
59 Deque <Character > stack = new ArrayDeque <>();
You can’t perform that action at this time.
0 commit comments