# Excel Sheet Column Title

<https://leetcode.com/problems/excel-sheet-column-title/description/>

> Given a positive integer, return its corresponding column title as appear in an Excel sheet.

## Thoughts

本质上是进制转换, 只是这里是26进制. 26进制余数可以取0 \~ 25, 但由于结果要求从1\~26, 因此每次要减1.

举个例子, 28 = AB, 如果不-1取余得到2, 2 + A = C, 然后28 / 26 = 1, 再对26取余得到B, 即BC. 因此我们要每次都对n - 1.

## Code

```
class Solution {
    public String convertToTitle(int n) {
        StringBuilder sb = new StringBuilder();
        while (n > 0) {
            n--;
            sb.insert(0, (char)('A' + n % 26));
            n /= 26;
        }

        return sb.toString();
    }
}
```

## Analysis

时空复杂度O(lgN).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hao-fu-1.gitbook.io/oj/math/jin-zhi-zhuan-huan/excel-sheet-column-title.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
