マツシタのお勉強

substring

'a'と'b'でパターンマッチ

問題 文字列wordとパターンを表すpatternが入力値として与えれる。patternは'a'と'b'のみで構成されている。wordがpatternにマッチするか否かを求める問題。 例 word = “catcatgocatgo”, pattern = “abbab” a -> cat b -> go とすればwordはpatternにマッチ…

Longest Substring Without Repeating Characters

問題 文字列sが与えられ、以下の条件での最大の部分文字列の長さを出力する。 条件は、部分文字列内には同じ文字は被ってはいけない。 leetcode.com 解法 ハッシュマップを用いて、キーに文字をバリューにその文字が出現した場所(index)を保存することでO(N…

340. Longest Substring with At Most K Distinct Characters : Past Google Interview

Problem https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters/ Given a string, find the length of the longest substring T that contains at most k distinct characters. For example, Given s = "eceba" and k = 2, T…