<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: 花花酱 Leetcode 139. Word Break	</title>
	<atom:link href="https://zxi.mytechroad.com/blog/leetcode/leetcode-139-word-break/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/leetcode/leetcode-139-word-break/</link>
	<description></description>
	<lastBuildDate>Wed, 29 Aug 2018 05:42:40 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>
	<item>
		<title>
		By: longspring		</title>
		<link>https://zxi.mytechroad.com/blog/leetcode/leetcode-139-word-break/#comment-13</link>

		<dc:creator><![CDATA[longspring]]></dc:creator>
		<pubDate>Sun, 10 Jun 2018 00:59:45 +0000</pubDate>
		<guid isPermaLink="false">http://zxi.mytechroad.com/blog/?p=49#comment-13</guid>

					<description><![CDATA[More clear code below FYI.

class Solution {
public:
    bool wordBreak(string s, vector&#038; wordDict) {
        for (auto word : wordDict)
            m.emplace(word, true);
        return wBreak(s, wordDict);
    }
    
    bool wBreak(string &#038;s, vector&#038; wordDict) {
        if (m.count(s)) return m[s];

        for (auto word : wordDict) {
            string left = s.substr(0, word.size());
            if (!m.count(left) &#124;&#124; m[left] == false) continue;

            string right = s.substr(word.size());
            if (wBreak(right, wordDict)) return m[s]=true;
        }
        return m[s]=false;
    }
private:
    unordered_map m;
};]]></description>
			<content:encoded><![CDATA[<p>More clear code below FYI.</p>
<p>class Solution {<br />
public:<br />
    bool wordBreak(string s, vector&amp; wordDict) {<br />
        for (auto word : wordDict)<br />
            m.emplace(word, true);<br />
        return wBreak(s, wordDict);<br />
    }</p>
<p>    bool wBreak(string &amp;s, vector&amp; wordDict) {<br />
        if (m.count(s)) return m[s];</p>
<p>        for (auto word : wordDict) {<br />
            string left = s.substr(0, word.size());<br />
            if (!m.count(left) || m[left] == false) continue;</p>
<p>            string right = s.substr(word.size());<br />
            if (wBreak(right, wordDict)) return m[s]=true;<br />
        }<br />
        return m[s]=false;<br />
    }<br />
private:<br />
    unordered_map m;<br />
};</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
