
g0101_0200.s0139_word_break.Solution.cs Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-all Show documentation
Show all versions of leetcode-in-all Show documentation
104 LeetCode algorithm problem solutions
The newest version!
namespace LeetCodeNet.G0101_0200.S0139_word_break {
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table
// #Dynamic_Programming #Trie #Memoization #Algorithm_II_Day_15_Dynamic_Programming
// #Dynamic_Programming_I_Day_9 #Udemy_Dynamic_Programming #Big_O_Time_O(M+max*N)_Space_O(M+N+max)
// #2024_01_09_Time_64_ms_(98.44%)_Space_49.2_MB_(10.24%)
public class Solution {
private Dictionary visited = new();
private HashSet? set;
public bool WordBreak(string s, IList wordDict) {
set = new HashSet(wordDict);
return CheckWordBreak(s);
}
public bool CheckWordBreak(string s) {
if (visited.ContainsKey(s)) {
return visited[s];
}
if (set.Contains(s)) {
return true;
}
for (int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy