<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>lambda Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/lambda/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/lambda/</link>
	<description></description>
	<lastBuildDate>Fri, 31 Dec 2021 22:28:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>lambda Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/lambda/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 1967. Number of Strings That Appear as Substrings in Word</title>
		<link>https://zxi.mytechroad.com/blog/string/leetcode-1967-number-of-strings-that-appear-as-substrings-in-word/</link>
					<comments>https://zxi.mytechroad.com/blog/string/leetcode-1967-number-of-strings-that-appear-as-substrings-in-word/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Fri, 31 Dec 2021 22:26:30 +0000</pubDate>
				<category><![CDATA[String]]></category>
		<category><![CDATA[count_if]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[lambda]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=9339</guid>

					<description><![CDATA[<p>Given an array of strings&#160;patterns&#160;and a string&#160;word, return&#160;the&#160;number&#160;of strings in&#160;patterns&#160;that exist as a&#160;substring&#160;in&#160;word. A&#160;substring&#160;is a contiguous sequence of characters within a string. Example 1: Input:&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/string/leetcode-1967-number-of-strings-that-appear-as-substrings-in-word/">花花酱 LeetCode 1967. Number of Strings That Appear as Substrings in Word</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Given an array of strings&nbsp;<code>patterns</code>&nbsp;and a string&nbsp;<code>word</code>, return&nbsp;<em>the&nbsp;<strong>number</strong>&nbsp;of strings in&nbsp;</em><code>patterns</code><em>&nbsp;that exist as a&nbsp;<strong>substring</strong>&nbsp;in&nbsp;</em><code>word</code>.</p>



<p>A&nbsp;<strong>substring</strong>&nbsp;is a contiguous sequence of characters within a string.</p>



<p><strong>Example 1:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> patterns = ["a","abc","bc","d"], word = "abc"
<strong>Output:</strong> 3
<strong>Explanation:</strong>
- "a" appears as a substring in "abc".
- "abc" appears as a substring in "abc".
- "bc" appears as a substring in "abc".
- "d" does not appear as a substring in "abc".
3 of the strings in patterns appear as a substring in word.
</pre>



<p><strong>Example 2:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> patterns = ["a","b","c"], word = "aaaaabbbbb"
<strong>Output:</strong> 2
<strong>Explanation:</strong>
- "a" appears as a substring in "aaaaabbbbb".
- "b" appears as a substring in "aaaaabbbbb".
- "c" does not appear as a substring in "aaaaabbbbb".
2 of the strings in patterns appear as a substring in word.
</pre>



<p><strong>Example 3:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> patterns = ["a","a","a"], word = "ab"
<strong>Output:</strong> 3
<strong>Explanation:</strong> Each of the patterns appears as a substring in word "ab".
</pre>



<p><strong>Constraints:</strong></p>



<ul><li><code>1 &lt;= patterns.length &lt;= 100</code></li><li><code>1 &lt;= patterns[i].length &lt;= 100</code></li><li><code>1 &lt;= word.length &lt;= 100</code></li><li><code>patterns[i]</code>&nbsp;and&nbsp;<code>word</code>&nbsp;consist of lowercase English letters.</li></ul>



<h2><strong>Solution: Brute Force</strong></h2>



<p>We can use <a href="https://en.cppreference.com/w/cpp/algorithm/count" target="_blank" rel="noreferrer noopener">count_if</a> for 1-liner.</p>



<p>Time complexity: O(m*n)<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  int numOfStrings(vector&lt;string&gt;&amp; patterns, string word) {
    return count_if(begin(patterns), end(patterns), [&amp;](string&amp; p) {
      return word.find(p) != string::npos;
    });
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/string/leetcode-1967-number-of-strings-that-appear-as-substrings-in-word/">花花酱 LeetCode 1967. Number of Strings That Appear as Substrings in Word</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/string/leetcode-1967-number-of-strings-that-appear-as-substrings-in-word/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
