Runtime: 15 ms, faster than 71.70% of Java online submissions for Repeated Substring Pattern.
Memory Usage: 36.5 MB, less than 100.00% of Java online submissions for Repeated Substring Pattern.
classSolution{publicbooleanrepeatedSubstringPattern(String s){//abcabcabcabcchar[] arr = s.toCharArray();// distancefor(int i=1; i<=arr.length/2; i++){if(arr.length % i !=0){continue;}boolean allSame =true;// 각 파티션
second :for(int j=i; j<arr.length; j+=i){// 파티션의 distacne 까지 비교for(int k=0; k<i; k++){if(arr[k]!= arr[j+k]){
allSame =false;break second;}}}if(allSame){returntrue;}}returnfalse;}}
No comments:
Post a Comment