Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions container-with-most-water/hoyeongkwak.java
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;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint error 나서 마지막 줄에 엔터 추가하셔야 될 거 같습니다!

80 changes: 80 additions & 0 deletions design-add-and-search-words-data-structure/hoyeongkwak.java
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);
*/

24 changes: 24 additions & 0 deletions valid-parentheses/hoyeongkwak.java
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
Copy link
Member

Choose a reason for hiding this comment

The 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();
}
}
Loading