# Excel Sheet Column Title（math)

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

For example:

```
  1 -> A
    2 -> B
    3 -> C
    ...
    26 -> Z
    27 -> AA
    28 -> AB 
    ...
```

**Example 1:**

```
Input:
 1

Output:
 "A"
```

**Example 2:**

```
Input:
 28

Output:
 "AB"
```

**Example 3:**

```
Input:
 701

Output:
 "ZY"
```

分析

就是模拟十进制数，个位数%，十位数/，注意这里是n-1，不是N

python ord 和 chr

```
class Solution(object):
    def convertToTitle(self, n):
        """
        :type n: int
        :rtype: str
        """
        s = ''
        while n>0:
            rem = (n-1)%26
            s=chr(ord('A')+rem)+s #想象 A+25 =Z 所以要n-1
            n=(n-1)/26
        return s
```

分治

每次递归结果+最低位的char

```
class Solution(object):
    def convertToTitle(self, n):
        """
        :type n: int
        :rtype: str
        """
        return "" if n==0 else self.convertToTitle((n-1)/26)+chr((n-1)%26+ord('A'))
```


---

# 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://nataliekung.gitbook.io/ladder_code/facebook/excel-sheet-column-titlemath.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.
