-
171. Excel Sheet Column Number릿코드(LEETCODE) 2020. 2. 6. 16:15반응형
https://leetcode.com/problems/excel-sheet-column-number/
class Solution { public: int titleToNumber(string s) { reverse(s.begin(), s.end()); const int size = s.size(); long long sol = s[0] - 'A'+ 1; for (int i = 1; i < size; i++) { char code = s[i] - 'A' + 1; long long cand = pow(26, i) * code; sol += cand; } return sol; } };
반응형'릿코드(LEETCODE)' 카테고리의 다른 글
1317. Convert Integer to the Sum of Two No-Zero Integers (2) 2020.02.07 383. Ransom Note (2) 2020.02.07 168. Excel Sheet Column Title (0) 2020.02.06 581. Shortest Unsorted Continuous Subarray (0) 2020.02.05 709. To Lower Case (0) 2020.02.03