0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

day 2 at leetcode

0
Posted at
  1. Greatest Common Divisor of Strings
class Solution:
    def gcdOfStrings(self, str1: str, str2: str) -> str:
        if str1 + str2 != str2 + str1: #str1がstr2で割り切れるのなら順番を変えても同様になるはず
            return ""
        
        # 長さのGCD
        length = math.gcd(len(str1), len(str2)) #各strの長さの最大公約数を求める        
        return str1[:length]#str1からその長さを持ってくる。

難しい、最初のifの部分を思いついて、mathライブラリを知っていて、かつ長さからのアプローチがいる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?