題目:給定兩個字符串a(chǎn)和b韧涨,判斷字符串b是否是由a字符串旋轉(zhuǎn)而成.
核心代碼:
<pre><code>` func isRotation(orginal:String,rotation:String) -> Bool {
let len:Int = orginal.characters.count
if len > 0 && len == rotation.characters.count {
let mergeStr:String = orginal + orginal
return mergeStr.contains(rotation)
}
return false
}
`</code></pre>
測試代碼:
<pre><code>var originalStr:String = "FlyElephant" var rotationStr:String = "antFlyEleph" var result:Bool = myString.isRotation(orginal: originalStr, rotation: rotationStr) print("\(rotationStr)是\(originalStr)的結(jié)果\(result)")
</code></pre>