Skip to content

Commit c6383a2

Browse files
committed
solve problem Excel Sheet Column Title
1 parent 2011acc commit c6383a2

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ All solutions will be accepted!
2525
|821|[Shortest Distance To A Character](https://leetcode-cn.com/problems/shortest-distance-to-a-character/description/)|[java/py/js](./algorithms/ShortestDistanceToACharacter)|Easy|
2626
|371|[Sum Of Two Integers](https://leetcode-cn.com/problems/sum-of-two-integers/description/)|[java/py/js](./algorithms/SumOfTwoIntegers)|Easy|
2727
|171|[Excel Sheet Column Number](https://leetcode-cn.com/problems/excel-sheet-column-number/description/)|[java/py/js](./algorithms/ExcelSheetColumnNumber)|Easy|
28+
|168|[Excel Sheet Column Title](https://leetcode-cn.com/problems/excel-sheet-column-title/description/)|[java/py/js](./algorithms/ExcelSheetColumnTitle)|Easy|
2829
|13|[Roman To Integer](https://leetcode-cn.com/problems/roman-to-integer/description/)|[java/py/js](./algorithms/RomanToInteger)|Easy|
2930
|155|[Min Stack](https://leetcode-cn.com/problems/min-stack/description/)|[java/py/js](./algorithms/MinStack)|Easy|
3031
|232|[Implement Queue Using Stacks](https://leetcode-cn.com/problems/implement-queue-using-stacks/description/)|[java/py/js](./algorithms/ImplementQueueUsingStacks)|Easy|
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Excel Sheet Column Title
2+
This problem is easy to solve
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public String convertToTitle(int n) {
3+
String res = "";
4+
5+
while (n > 0) {
6+
int mod = n % 26;
7+
n /= 26;
8+
9+
if (mod == 0) {
10+
n--;
11+
mod = 26;
12+
}
13+
14+
res = new String(new char[]{(char) (mod + 64)}) + res;
15+
}
16+
17+
return res;
18+
}
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {number} n
3+
* @return {string}
4+
*/
5+
var convertToTitle = function(n) {
6+
let res = ''
7+
8+
while (n > 0) {
9+
let mod = n % 26
10+
n = parseInt(n / 26)
11+
12+
if (mod === 0) {
13+
mod = 26
14+
n--
15+
}
16+
17+
res = String.fromCharCode(mod + 64) + res
18+
}
19+
20+
return res
21+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution(object):
2+
def convertToTitle(self, n):
3+
"""
4+
:type n: int
5+
:rtype: str
6+
"""
7+
res = ''
8+
9+
while n > 0:
10+
mod = n % 26
11+
n /= 26
12+
13+
if mod == 0:
14+
n -= 1
15+
mod = 26
16+
res = chr(mod + 64) + res
17+
18+
return res

0 commit comments

Comments
 (0)