File tree 2 files changed +19
-0
lines changed
2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 163
163
167|[ Two Sum II - Input Array Is Sorted] ( ./0167-two-sum-ii-input-array-is-sorted.js ) |Easy|
164
164
168|[ Excel Sheet Column Title] ( ./0168-excel-sheet-column-title.js ) |Easy|
165
165
169|[ Majority Element] ( ./0169-majority-element.js ) |Easy|
166
+ 171|[ Excel Sheet Column Number] ( ./0171-excel-sheet-column-number.js ) |Easy|
166
167
179|[ Largest Number] ( ./0179-largest-number.js ) |Medium|
167
168
187|[ Repeated DNA Sequences] ( ./0187-repeated-dna-sequences.js ) |Medium|
168
169
189|[ Rotate Array] ( ./0189-rotate-array.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 171. Excel Sheet Column Number
3
+ * https://leetcode.com/problems/excel-sheet-column-number/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given a string columnTitle that represents the column title as appears in
7
+ * an Excel sheet, return its corresponding column number.
8
+ */
9
+
10
+ /**
11
+ * @param {string } columnTitle
12
+ * @return {number }
13
+ */
14
+ var titleToNumber = function ( columnTitle ) {
15
+ return columnTitle . split ( '' ) . reduce ( ( result , c , i ) => {
16
+ return result + ( c . charCodeAt ( ) - 64 ) * Math . pow ( 26 , columnTitle . length - ( i + 1 ) ) ;
17
+ } , 0 ) ;
18
+ } ;
You can’t perform that action at this time.
0 commit comments