Re: [闲聊] 每日LeetCode

楼主: Rushia (みけねこ的鼻屎)   2023-08-21 18:02:48
https://leetcode.com/problems/repeated-substring-pattern/description/
459. Repeated Substring Pattern
给你一个字串s,判断s是否可以被切成多个完全相同的子字串。
Example 1:
Input: s = "abab"
Output: true
Explanation: It is the substring "ab" twice.
Example 2:
Input: s = "aba"
Output: false
Example 3:
Input: s = "abcabcabcabc"
Output: true
Explanation: It is the substring "abc" four times or the substring "abcabc"
twice.
思路:
1.如果一个s可以被切成多个子字串,那么他的:
1) 长度一定大于1
2) 子字串长度一定小于等于s长度/2
3) 子字串长度一定可以整除s长度
2.利用上面三点去切出所有长度为 1~s长度除二 的子串,并判断全由子字串组成的新字串
是否等于s即可。
Java Code:

Links booklink

Contact Us: admin [ a t ] ucptt.com