Skip to content
Merged
Changes from 1 commit
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 word-break/hyer0705.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
// using set
function wordBreak(s: string, wordDict: string[]): boolean {
const sLen = s.length;

const dp: boolean[] = new Array(sLen + 1).fill(false);
dp[0] = true;

const wordSet = new Set<string>(wordDict);

for (let i = 1; i <= sLen; i++) {
for (let j = 0; j < i; j++) {
if (dp[j] && wordSet.has(s.substring(j, i))) {
dp[i] = true;
break;
}
}
}

return dp[sLen];
}

// using trie
Copy link
Contributor

Choose a reason for hiding this comment

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

고생하셨습니다! 코드가 이해하기 좋고, 매우 깔끔하네요 👍 근데 다른 문제의 코드가 들어있는 것 같아요..!!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trie랑 TNode class 때문에 그러신 건가요? 해당 문제를 trie로도 풀 수 있다기에 한 번 풀어봤습니다.

class TNode {
isEndOf: boolean;
children: Map<string, TNode>;
Expand Down