일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- 매일
- 화상영어
- realclass
- English
- 스탭퍼
- 30분
- 사이드
- 영어공부
- leetcode
- 파비최
- 괜찮음
- Problem Solving
- 영어원서읽기
- 뭐든
- 읽기
- 3줄정리
- 쓰릴오브파이트
- Daily Challenge
- 리얼 클래스
- 미드시청
- 프로젝트
- 잡생각
- Writing
- 월간
- 링피트
- 개발자
- 운동
- FIT XR
- 만화도
- 10분
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.02.01 Today's Challenge 본문
https://leetcode.com/problems/greatest-common-divisor-of-strings/
Greatest Common Divisor of Strings - LeetCode
Greatest Common Divisor of Strings - For two strings s and t, we say "t divides s" if and only if s = t + ... + t (i.e., t is concatenated with itself one or more times). Given two strings str1 and str2, return the largest string x such that x divides both
leetcode.com
GCD 를 구하면 됨
class Solution:
def gcdOfStrings(self, str1: str, str2: str) -> str:
if str1 + str2 != str2 + str1:
return ""
max_length = gcd(len(str1), len(str2))
return str1[:max_length]
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.02.03 Today's Challenge (0) | 2023.02.03 |
---|---|
2023.02.02 Today's Challenge (0) | 2023.02.02 |
2023.01.31 Today's Challenge (0) | 2023.01.31 |
2023.01.30 Today's Challenge (1) | 2023.01.30 |
2023.01.29 Today's Challenge (0) | 2023.01.29 |
Comments