Skip to content

Commit

Permalink
[Math] Refactor solution to Excel Sheet Column Number
Browse files Browse the repository at this point in the history
  • Loading branch information
soapyigu authored Sep 24, 2019
1 parent 36a55b1 commit 313a70f
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions Math/ExcelSheetColumnNumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@

class ExcelSheetColumnNumber {
func titleToNumber(s: String) -> Int {
var res = 0
let scalarsOfA = "A".unicodeScalars
var result = 0

for char in s.characters {
let scalars = String(char).unicodeScalars
let current = Int(scalars[scalars.startIndex].value - scalarsOfA[scalarsOfA.startIndex].value) + 1
res = res * 26 + current
for c in s.unicodeScalars {
let value = Int(c.value) - 64
result = (result * 26) + value
}

return res
return result
}
}
}

0 comments on commit 313a70f

Please sign in to comment.