File tree 6 files changed +81
-12
lines changed
solution/0100-0199/0171.Excel Sheet Column Number
6 files changed +81
-12
lines changed Original file line number Diff line number Diff line change @@ -92,9 +92,9 @@ var reverseWords = function (s) {
92
92
};
93
93
```
94
94
95
- ### ** C++ **
95
+ ### ** Go **
96
96
97
- ``` cpp
97
+ ``` go
98
98
func reverseWords (s string ) string {
99
99
s = strings.Trim (s, " " )
100
100
n := len (s) - 1
Original file line number Diff line number Diff line change 52
52
<!-- 这里可写当前语言的特殊实现逻辑 -->
53
53
54
54
``` python
55
-
55
+ class Solution :
56
+ def titleToNumber (self , columnTitle : str ) -> int :
57
+ res = 0
58
+ for c in columnTitle:
59
+ res = res * 26 + (ord (c) - ord (' A' ) + 1 )
60
+ return res
56
61
```
57
62
58
63
### ** Java**
59
64
60
65
<!-- 这里可写当前语言的特殊实现逻辑 -->
61
66
62
67
``` java
68
+ class Solution {
69
+ public int titleToNumber (String columnTitle ) {
70
+ int res = 0 ;
71
+ for (char c : columnTitle. toCharArray()) {
72
+ res = res * 26 + (c - ' A' + 1 );
73
+ }
74
+ return res;
75
+ }
76
+ }
77
+ ```
63
78
79
+ ### ** C++**
80
+
81
+ ``` cpp
82
+ class Solution {
83
+ public:
84
+ int titleToNumber(string columnTitle) {
85
+ int res = 0;
86
+ for (char c : columnTitle) {
87
+ res = res * 26 + (c - 'A' + 1);
88
+ }
89
+ return res;
90
+ }
91
+ };
64
92
```
65
93
66
94
### **...**
Original file line number Diff line number Diff line change @@ -65,13 +65,41 @@ AB -> 28
65
65
### ** Python3**
66
66
67
67
``` python
68
-
68
+ class Solution :
69
+ def titleToNumber (self , columnTitle : str ) -> int :
70
+ res = 0
71
+ for c in columnTitle:
72
+ res = res * 26 + (ord (c) - ord (' A' ) + 1 )
73
+ return res
69
74
```
70
75
71
76
### ** Java**
72
77
73
78
``` java
79
+ class Solution {
80
+ public int titleToNumber (String columnTitle ) {
81
+ int res = 0 ;
82
+ for (char c : columnTitle. toCharArray()) {
83
+ res = res * 26 + (c - ' A' + 1 );
84
+ }
85
+ return res;
86
+ }
87
+ }
88
+ ```
74
89
90
+ ### ** C++**
91
+
92
+ ``` cpp
93
+ class Solution {
94
+ public:
95
+ int titleToNumber(string columnTitle) {
96
+ int res = 0;
97
+ for (char c : columnTitle) {
98
+ res = res * 26 + (c - 'A' + 1);
99
+ }
100
+ return res;
101
+ }
102
+ };
75
103
```
76
104
77
105
### **...**
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ int titleToNumber (string columnTitle) {
4
+ int res = 0 ;
5
+ for (char c : columnTitle) {
6
+ res = res * 26 + (c - ' A' + 1 );
7
+ }
8
+ return res;
9
+ }
10
+ };
Original file line number Diff line number Diff line change 1
1
class Solution {
2
- public int titleToNumber (String s ) {
3
- char [] cs = s .toCharArray ();
4
- int n = 0 ;
5
- int p = 1 ;
6
- for (int i = cs .length -1 ; i >= 0 ; i --) {
7
- n += (cs [i ]-'A' +1 )*p ;
8
- p *= 26 ;
2
+ public int titleToNumber (String columnTitle ) {
3
+ int res = 0 ;
4
+ for (char c : columnTitle .toCharArray ()) {
5
+ res = res * 26 + (c - 'A' + 1 );
9
6
}
10
- return n ;
7
+ return res ;
11
8
}
12
9
}
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def titleToNumber (self , columnTitle : str ) -> int :
3
+ res = 0
4
+ for c in columnTitle :
5
+ res = res * 26 + (ord (c ) - ord ('A' ) + 1 )
6
+ return res
You can’t perform that action at this time.
0 commit comments