-
-
Notifications
You must be signed in to change notification settings - Fork 247
[hoyeongkwak] Week6 Solutions #1873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hoyeongkwak
wants to merge
3
commits into
DaleStudy:main
Choose a base branch
from
hoyeongkwak:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+126
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
Time Complexity : O(n) | ||
Space Complexity : O(1) | ||
*/ | ||
class Solution { | ||
public int maxArea(int[] height) { | ||
int left = 0; | ||
int right = height.length - 1; | ||
int area = 0; | ||
|
||
while (left < right) { | ||
int currentArea = (right - left) * Math.min(height[left], height[right]); | ||
area = Math.max(area, currentArea); | ||
if (height[left] < height[right]) { | ||
left++; | ||
} else { | ||
right--; | ||
} | ||
} | ||
return area; | ||
} | ||
} | ||
80 changes: 80 additions & 0 deletions
80
design-add-and-search-words-data-structure/hoyeongkwak.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
m : word length | ||
n : Trie node count | ||
addWord | ||
Time Complexity: O(m) | ||
|
||
search | ||
Time Complexity: O(n) | ||
|
||
Space Complexity: O(26 × N × M) | ||
|
||
Trie + Dfs | ||
*/ | ||
|
||
class WordDictionary { | ||
class TrieNode { | ||
TrieNode[] children; | ||
boolean isEnd; | ||
|
||
public TrieNode() { | ||
children = new TrieNode[26]; | ||
isEnd = false; | ||
} | ||
} | ||
|
||
private TrieNode root; | ||
|
||
public WordDictionary() { | ||
root = new TrieNode(); | ||
} | ||
|
||
public void addWord(String word) { | ||
TrieNode current = root; | ||
|
||
for (char str : word.toCharArray()) { | ||
int idx = str - 'a'; | ||
if (current.children[idx] == null) { | ||
current.children[idx] = new TrieNode(); | ||
} | ||
current = current.children[idx]; | ||
} | ||
current.isEnd = true; | ||
} | ||
|
||
public boolean search(String word) { | ||
return dfsSearch(word, 0, root); | ||
} | ||
|
||
private boolean dfsSearch(String word, int idx, TrieNode node) { | ||
if (idx == word.length()) { | ||
return node.isEnd; | ||
} | ||
|
||
char c = word.charAt(idx); | ||
if (c == '.') { | ||
for (int i = 0 ; i < 26; i++) { | ||
if (node.children[i] != null) { | ||
if (dfsSearch(word, idx + 1, node.children[i])) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} else { | ||
int charIdx = c - 'a'; | ||
if (node.children[charIdx] == null) { | ||
return false; | ||
} | ||
return dfsSearch(word, idx + 1, node.children[charIdx]); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Your WordDictionary object will be instantiated and called as such: | ||
* WordDictionary obj = new WordDictionary(); | ||
* obj.addWord(word); | ||
* boolean param_2 = obj.search(word); | ||
*/ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class Solution { | ||
public boolean isValid(String s) { | ||
if (s == null || s.length() % 2 != 0) { | ||
return false; | ||
} | ||
Stack<Character> stack = new Stack<>(); | ||
HashMap<Character, Character> strList = new HashMap<>(); | ||
strList.put(')', '('); | ||
strList.put(']', '['); | ||
strList.put('}', '{'); | ||
Comment on lines
+7
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HashMap 사용하는 풀이는 아예 생각 못했는데 좋은 접근이네요! |
||
|
||
for (char c : s.toCharArray()) { | ||
if (strList.containsKey(c)) { | ||
if (stack.isEmpty() || stack.pop() != strList.get(c)) { | ||
return false; | ||
} | ||
} else { | ||
stack.push(c); | ||
} | ||
} | ||
|
||
return stack.isEmpty(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lint error 나서 마지막 줄에 엔터 추가하셔야 될 거 같습니다!