Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit984e54f

Browse files
author
zongyanqi
committed
add Easy_171_Excel_Sheet_Column_Number
1 parent4f488e4 commit984e54f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

‎Easy_171_Excel_Sheet_Column_Number.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Given a column title as appear in an Excel sheet, return its corresponding column number.
3+
4+
For example:
5+
6+
A -> 1
7+
B -> 2
8+
C -> 3
9+
...
10+
Z -> 26
11+
AA -> 27
12+
AB -> 28
13+
14+
*/
15+
16+
/**
17+
*@param {string} s
18+
*@return {number}
19+
*/
20+
vartitleToNumber=function(s){
21+
22+
varnum=0;
23+
varaCode='A'.charCodeAt(0);
24+
for(vari=0;i<s.length;i++){
25+
varn=1+s.charCodeAt(i)-aCode;
26+
num=num*26+n;
27+
}
28+
returnnum;
29+
};
30+
31+
console.log(titleToNumber('AA'));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp