LeetCode 171 Excel Sheet Column Number

Tag: 数学类题目 LeetCode Posted on 2022-03-04 23:34:22 Edited on 2022-03-04 23:34:22 Views: 140

概述

https://leetcode.com/problems/excel-sheet-column-number/

解法

class Solution {
public:
    int titleToNumber(string columnTitle) {
        int ans = 0;
        for (auto c : columnTitle) {
            ans *= 26;
            ans += c - 'A' + 1;
        }
        return ans;
    }
};

未经允许,禁止转载,本文源站链接:https://iamazing.cn/