爬楼梯

1--

 private func exchangeStr(str:String) -> String{
         return str.replacingOccurrences(of: " ", with: "%20")
}

2--

 override func viewDidLoad() {
    super.viewDidLoad()
    print( addTwo(str1: "4->6->3", str2: "9->8->7") )
   }

private func addTwo(str1:String,str2:String) -> String{
    
    let strArr1 = str1.components(separatedBy: "->")
    let strArr2 = str2.components(separatedBy: "->")
    
    var emptyStr1 = ""
    var emptyStr2 = ""
    
    for i in strArr1.reversed() {
        emptyStr1 += i
    }
    for i in strArr2.reversed() {
        emptyStr2 += i
    }
    
    let  countNum =  Int(emptyStr1)! + Int(emptyStr2)!
    let countStr = String(countNum)
    
    var finalStr = ""
    for char in countStr.reversed() {
        finalStr = finalStr + String(char) + "->"
    }
    let index = finalStr.index(finalStr.endIndex, offsetBy: -2)
    
    return String(finalStr[..

3--

 private func calculateMaxCount(ladder: UInt) -> UInt{
    
    guard ladder != 0 else {
        print("不能为0")
        return 0
    }
    
    switch ladder {
    case 1:
        return 1
    case 2 :
        return 2
    case 3:
        return 4
        
    default:
        return calculateMaxCount(ladder: ladder - 1) + calculateMaxCount(ladder: ladder - 2) + calculateMaxCount(ladder:ladder - 3)
        
    }
}

你可能感兴趣的:(爬楼梯)