<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>LeetCode 139 on Jeanphilo Blog</title><link>https://shio-chan-dev.github.io/jeanblog/tags/leetcode-139/</link><description>Recent content in LeetCode 139 on Jeanphilo Blog</description><generator>Hugo -- 0.166.0</generator><language>en-us</language><lastBuildDate>Tue, 22 Sep 2026 12:00:00 +0800</lastBuildDate><atom:link href="https://shio-chan-dev.github.io/jeanblog/tags/leetcode-139/index.xml" rel="self" type="application/rss+xml"/><item><title>LeetCode 139: Word Break, Starting from Prefix Reachability</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/139-word-break/</link><pubDate>Tue, 22 Sep 2026 12:00:00 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/139-word-break/</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;h3 id="input-and-output"&gt;Input and Output&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Input: a string &lt;code&gt;s&lt;/code&gt; and a list of strings &lt;code&gt;wordDict&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Every element in &lt;code&gt;wordDict&lt;/code&gt; is an available word, and the same word may be reused&lt;/li&gt;
&lt;li&gt;Output: return &lt;code&gt;True&lt;/code&gt; if &lt;code&gt;s&lt;/code&gt; can be split into one or more dictionary words; otherwise, return &lt;code&gt;False&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;The split must cover the entire string without skipping or reordering characters&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="examples"&gt;Examples&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: s = &amp;#34;leetcode&amp;#34;, wordDict = [&amp;#34;leet&amp;#34;, &amp;#34;code&amp;#34;]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: True
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Explanation: &amp;#34;leetcode&amp;#34; can be split into &amp;#34;leet&amp;#34; + &amp;#34;code&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: s = &amp;#34;applepenapple&amp;#34;, wordDict = [&amp;#34;apple&amp;#34;, &amp;#34;pen&amp;#34;]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: True
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Explanation: &amp;#34;apple&amp;#34; + &amp;#34;pen&amp;#34; + &amp;#34;apple&amp;#34;; the same word may be reused
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: s = &amp;#34;catsandog&amp;#34;, wordDict = [&amp;#34;cats&amp;#34;, &amp;#34;dog&amp;#34;, &amp;#34;sand&amp;#34;, &amp;#34;and&amp;#34;, &amp;#34;cat&amp;#34;]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: False
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Explanation: some prefixes can be formed, but the split cannot cover the entire string
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="constraints"&gt;Constraints&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;1 &amp;lt;= s.length &amp;lt;= 300&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;1 &amp;lt;= wordDict.length &amp;lt;= 1000&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;1 &amp;lt;= wordDict[i].length &amp;lt;= 20&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;s&lt;/code&gt; and &lt;code&gt;wordDict[i]&lt;/code&gt; contain only lowercase English letters&lt;/li&gt;
&lt;li&gt;All strings in &lt;code&gt;wordDict&lt;/code&gt; are unique&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="step-1-make-the-completed-prefix-visible"&gt;Step 1: Make the Completed Prefix Visible&lt;/h2&gt;
&lt;p&gt;Start with one concrete question. For &lt;code&gt;s = &amp;quot;leetcode&amp;quot;&lt;/code&gt;, before deciding whether the whole string can be split, can we record how much of it has already been completed?&lt;/p&gt;</description></item></channel></rss>