반응형
오늘 풀 문제는 Repeated Substring Pattern라는 문제이며
링크는 https://leetcode.com/problems/repeated-substring-pattern/입니다
위의 문제는 하나의 string이 substring의 반복으로 이루어져있는지 판단하는 문제였습니다
저는 string s의 길이의 약수마다 곱해서 s가 되는지 판단하는 알고리즘으로 풀었습니다
func repeatedSubstringPattern(s string) bool {
size := len(s)
for i:=1;i<size/2+1;i++{
if size%i == 0 && s == strings.Repeat(s[:i], size/i){
return true
}
}
return false
}
읽어주셔서 감사합니다
'Language > Go' 카테고리의 다른 글
[Golang으로 도전하는 Leetcode] All Elements in Two Binary Search Trees (0) | 2020.09.07 |
---|---|
[Golang으로 도전하는 Leetcode] Partition Labels (0) | 2020.09.05 |
[Golang으로 도전하는 Leetcode] Contains Duplicate III (0) | 2020.09.02 |
[Golang으로 도전하는 Leetcode] Largest Time for Given Digits (0) | 2020.09.02 |
[Golang으로 도전하는 Leetcode] Implement Rand10() Using Rand7()Solution (0) | 2020.08.30 |