My Swift Solution


  • 0
    C
    class Solution {
    func titleToNumber(s: String) -> Int {
    
        let scalarsOfA = "A".unicodeScalars
        var totalValue = 0
        for ch in s.characters {
            let scalars = String(ch).unicodeScalars
            let currentValue = Int(scalars[scalars.startIndex].value - scalarsOfA[scalarsOfA.startIndex].value) + 1
            totalValue = totalValue*26 + currentValue
        }
        return totalValue
       }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.