<?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>String on Shiglass</title>
    <link>https://hirotoshimizu.github.io/tags/string/</link>
    <description>Recent content in String on Shiglass</description>
    <generator>Hugo -- gohugo.io</generator>
    <lastBuildDate>Thu, 21 Oct 2021 05:16:53 +0900</lastBuildDate><atom:link href="https://hirotoshimizu.github.io/tags/string/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Isomorphic Strings</title>
      <link>https://hirotoshimizu.github.io/posts/isomorphic-strings/</link>
      <pubDate>Thu, 21 Oct 2021 05:16:53 +0900</pubDate>
      
      <guid>https://hirotoshimizu.github.io/posts/isomorphic-strings/</guid>
      <description>https://leetcode.com/problems/isomorphic-strings/
s と t をマッピングして考える。 この際、同じ文字なのに違う文字がマッピングされる場合
isomorphic にならない。
ex. foo bar
 | f → b | | o → a | | o → r |  | b → f | | a → o | | r → o | o が a と r にマッピングされているので、 isomorphic にならず、false になる。
class Solution: def isIsomorphic(self, s: str, t: str) -&amp;gt; bool: mapST, mapTS = {}, {} for c1, c2 in zip(s, t): if((c1 in mapST and mapST[c1] !</description>
    </item>
    
    <item>
      <title>Valid Anagram</title>
      <link>https://hirotoshimizu.github.io/posts/valid-anagram/</link>
      <pubDate>Wed, 20 Oct 2021 13:01:44 +0900</pubDate>
      
      <guid>https://hirotoshimizu.github.io/posts/valid-anagram/</guid>
      <description>anagram かどうかを調べるには s, t の出現する文字のカウントが同じなら anagram と言える。
回答方法は
 文字数をカウントし、s と t を比較する 文字数をカウントし、s と t を比較する(Counter を使う) sorted を使う  Input: s = &amp;ldquo;anagram&amp;rdquo;, t = &amp;ldquo;nagaram&amp;rdquo;
 文字数をカウントし、s と t を比較する  class Solution: def isAnagram(self, s: str, t: str) -&amp;gt; bool: if len(s)!= len(t): return False count_s, count_t = {}, {} for i in range(len(s)): count_s[s[i]] = 1 + count_s.get(s[i], 0) count_t[t[i]] = 1 + count_t.get(t[i], 0) for c in count_s: if count_s[c] !</description>
    </item>
    
    <item>
      <title>Valid Parentheses</title>
      <link>https://hirotoshimizu.github.io/posts/valid-parentheses/</link>
      <pubDate>Wed, 22 Sep 2021 20:06:14 +0900</pubDate>
      
      <guid>https://hirotoshimizu.github.io/posts/valid-parentheses/</guid>
      <description>https://leetcode.com/problems/valid-parentheses/
Prerequisite Hash Map Stack
最初にどのカッコがどの 括弧閉じ にマッチしているかわかるために HashMap を作る必要がある。 この際、括弧閉じ をキーにする。
for 文で list の中を確認し、 括弧開きは stack に入れる。
stack は 最後に入れたものから出すので、 括弧開き と 括弧閉じ がマッチしていれば、 stack から pop できる。
最後に stack に何も残らなければ、 全てがマッチして True を return する。
Time complexity: O(n) Mem complexity: O(n)
class Solution(object): def isValid(self, s): &amp;#34;&amp;#34;&amp;#34; :type s: str :rtype: bool &amp;#34;&amp;#34;&amp;#34; stack = [] closeToOpen = { &amp;#39;)&amp;#39; : &amp;#39;(&amp;#39;, &amp;#39;]&amp;#39; : &amp;#39;[&amp;#39;, &amp;#39;}&amp;#39; : &amp;#39;{&amp;#39; } for c in s: if c in closeToOpen: if stack and stack[-1] == closeToOpen[c]: stack.</description>
    </item>
    
  </channel>
</rss>
