Skip to content

Commit 6d691b7

Browse files
add 171
1 parent e30cbb2 commit 6d691b7

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ Your ideas/fixes/algorithms are more than welcome!
279279
|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|
280280
|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|
281281
|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
283283
|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
284284
|169|[Majority Element](https://leetcode.com/problems/majority-element/)|[Solution](../master/src/main/java/com/stevesun/solutions/MajorityElement.java)| O(n)|O(1) | Easy|
285285
|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|

src/main/java/com/stevesun/solutions/ExcelSheetColumnNumber.java renamed to src/main/java/com/stevesun/solutions/_171.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,15 @@
1212
AA -> 27
1313
AB -> 28
1414
*/
15-
public class ExcelSheetColumnNumber {
15+
public class _171 {
1616

17-
public static int titleToNumber(String s) {
17+
public int titleToNumber(String s) {
1818
char[] c = s.toCharArray();
1919
int result = 0;
2020
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
2222
}
23-
2423
return result;
2524
}
2625

27-
public static void main(String...strings){
28-
String s = "AB";
29-
System.out.println(titleToNumber(s));
30-
}
31-
3226
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}

0 commit comments

Comments
 (0)