File tree Expand file tree Collapse file tree 3 files changed +29
-10
lines changed
main/java/com/stevesun/solutions Expand file tree Collapse file tree 3 files changed +29
-10
lines changed Original file line number Diff line number Diff line change @@ -279,7 +279,7 @@ Your ideas/fixes/algorithms are more than welcome!
279
279
| 174| [ Dungeon Game] ( https://leetcode.com/problems/dungeon-game/ ) | [ Queue] ( ../master/src/main/java/com/stevesun/solutions/BSTIterator_using_q.java ) [ Stack] ( ../../blmaster/MEDIUM/src/medium/DungeonGame.java ) | O(?) | O(?) | Hard|
280
280
| 173| [ Binary Search Tree Iterator] ( https://leetcode.com/problems/binary-search-tree-iterator/ ) | [ Queue] ( ../master/src/main/java/com/stevesun/solutions/BSTIterator_using_q.java ) [ Stack] ( ../../blmaster/MEDIUM/src/medium/BSTIterator_using_stack.java ) | O(1) | O(h) | Medium|
281
281
|172|[ Factorial Trailing Zeroes] ( https://leetcode.com/problems/factorial-trailing-zeroes/ ) |[ Solution] ( ../master/src/main/java/com/stevesun/solutions/FactorialTrailingZeroes.java ) | O(logn)|O(1)| Easy
282
- |171|[ Excel Sheet Column Number] ( https://leetcode.com/problems/excel-sheet-column-number/ ) |[ Solution] ( ../master/src/main/java/com/stevesun/solutions/ExcelSheetColumnNumber .java ) | O(n)|O(1)| Easy
282
+ |171|[ Excel Sheet Column Number] ( https://leetcode.com/problems/excel-sheet-column-number/ ) |[ Solution] ( ../master/src/main/java/com/stevesun/solutions/_171 .java ) | O(n)|O(1)| Easy
283
283
|170|[ Two Sum III - Data structure design] ( https://leetcode.com/problems/two-sum-iii-data-structure-design/ ) |[ Solution] ( ../master/src/main/java/com/stevesun/solutions/_170.java ) | O(n)|O(n)| Easy
284
284
| 169| [ Majority Element] ( https://leetcode.com/problems/majority-element/ ) | [ Solution] ( ../master/src/main/java/com/stevesun/solutions/MajorityElement.java ) | O(n)| O(1) | Easy|
285
285
| 168| [ Excel Sheet Column Title] ( https://leetcode.com/problems/excel-sheet-column-title/ ) | [ Solution] ( ../master/src/main/java/com/stevesun/solutions/ExcelSheetColumnTitle.java ) | O(n)| O(1) | Easy|
Original file line number Diff line number Diff line change 12
12
AA -> 27
13
13
AB -> 28
14
14
*/
15
- public class ExcelSheetColumnNumber {
15
+ public class _171 {
16
16
17
- public static int titleToNumber (String s ) {
17
+ public int titleToNumber (String s ) {
18
18
char [] c = s .toCharArray ();
19
19
int result = 0 ;
20
20
for (int i = s .length ()-1 ; i >= 0 ; i --){
21
- result += (c [i ]-64 )* ((int ) Math .pow (26 , s .length ()-i -1 ));
21
+ result += (c [i ]-64 ) * ((int ) Math .pow (26 , s .length ()-i -1 ));//The ASCII value of A is 65
22
22
}
23
-
24
23
return result ;
25
24
}
26
25
27
- public static void main (String ...strings ){
28
- String s = "AB" ;
29
- System .out .println (titleToNumber (s ));
30
- }
31
-
32
26
}
Original file line number Diff line number Diff line change
1
+ package com .stevesun ;
2
+
3
+ import com .stevesun .solutions ._171 ;
4
+ import com .stevesun .solutions ._48 ;
5
+ import org .junit .BeforeClass ;
6
+ import org .junit .Test ;
7
+
8
+ import static org .junit .Assert .assertEquals ;
9
+
10
+ /**
11
+ * Created by stevesun on 5/13/17.
12
+ */
13
+ public class _171Test {
14
+ private static _171 test ;
15
+
16
+ @ BeforeClass
17
+ public static void setup (){
18
+ test = new _171 ();
19
+ }
20
+
21
+ @ Test
22
+ public void test1 (){
23
+ assertEquals (28 , test .titleToNumber ("AB" ));
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments