Skip to content

Commit b84ebc8

Browse files
committed
Add solution #168
1 parent ef1bfe7 commit b84ebc8

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
152|[Maximum Product Subarray](./0152-maximum-product-subarray.js)|Medium|
119119
160|[Intersection of Two Linked Lists](./0160-intersection-of-two-linked-lists.js)|Medium|
120120
167|[Two Sum II - Input Array Is Sorted](./0167-two-sum-ii-input-array-is-sorted.js)|Easy|
121+
168|[Excel Sheet Column Title](./0168-excel-sheet-column-title.js)|Easy|
121122
169|[Majority Element](./0169-majority-element.js)|Easy|
122123
179|[Largest Number](./0179-largest-number.js)|Medium|
123124
189|[Rotate Array](./0189-rotate-array.js)|Medium|
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* 168. Excel Sheet Column Title
3+
* https://leetcode.com/problems/excel-sheet-column-title/
4+
* Difficulty: Easy
5+
*
6+
* Given an integer columnNumber, return its corresponding column
7+
* title as it appears in an Excel sheet.
8+
*/
9+
10+
/**
11+
* @param {number} columnNumber
12+
* @return {string}
13+
*/
14+
var convertToTitle = function(columnNumber) {
15+
const n = columnNumber - 1;
16+
return n >= 0 && n < 26
17+
? String.fromCharCode(65 + n)
18+
: convertToTitle(parseInt(n / 26)) + convertToTitle((n % 26) + 1);
19+
};

0 commit comments

Comments
 (0)