File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -463,6 +463,46 @@ Swift:
463463 }
464464 }
465465```
466+ > 前缀表统一不减一
467+ ``` swift
468+ func repeatedSubstringPattern (_ s : String ) -> Bool {
469+
470+ let sArr = Array (s)
471+ let len = sArr.count
472+ if len == 0 {
473+ return false
474+ }
475+
476+ var next = Array .init (repeating : 0 , count : len)
477+ getNext (& next, sArr)
478+
479+ if next[len- 1 ] != 0 && len % (len - next[len- 1 ]) == 0 {
480+ return true
481+ }
482+
483+ return false
484+ }
485+
486+ // 前缀表不减一
487+ func getNext (_ next : inout [Int ], _ sArr :[Character ]) {
488+
489+ var j = 0
490+ next[0 ] = 0
491+
492+ for i in 1 ..< sArr.count {
466493
494+ while j > 0 && sArr[i] != sArr[j] {
495+ j = next[j- 1 ]
496+ }
497+
498+ if sArr[i] == sArr[j] {
499+ j += 1
500+ }
501+
502+ next[i] = j
503+ }
504+ }
505+
506+ ```
467507-----------------------
468508<div align =" center " ><img src =https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width =500 > </img ></div >
You can’t perform that action at this time.
0 commit comments