Skip to content

Commit 1294dec

Browse files
add solution for leetcode 67 168 171
1 parent 717b670 commit 1294dec

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-3
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
.vscode/settings.json
3+
.vscode/launch.json
4+
sqltools_20201017160659_98747.log

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,10 @@
255255
|174|[Dungeon Game](https://leetcode.com/problems/dungeon-game/) | |Hard|
256256
|173|[Binary Search Tree Iterator](https://leetcode.com/problems/binary-search-tree-iterator/) | |Medium|
257257
|172|[Factorial Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes/) | |Easy|
258-
|171|[Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number/) | |Easy|
258+
|171|[Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number/) | [Java](./algorithms/excelSheetColumnNumber/Solution.java) |Easy|
259259
|170|[Two Sum III - Data structure design](https://leetcode.com/problems/two-sum-iii-data-structure-design/) ♥ | |Easy|
260260
|169|[Majority Element](https://leetcode.com/problems/majority-element/) | |Easy|
261-
|168|[Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title/) | |Easy|
261+
|168|[Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title/) | [Java](./algorithms/excelSheetColumnTitle/Solution.java) |Easy|
262262
|167|[Two Sum II - Input array is sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/) ♥ | |Medium|
263263
|166|[Fraction to Recurring Decimal](https://leetcode.com/problems/fraction-to-recurring-decimal/) | |Medium|
264264
|165|[Compare Version Numbers](https://leetcode.com/problems/compare-version-numbers/) | |Easy|
@@ -359,7 +359,7 @@
359359
|70|[Climbing Stairs](https://leetcode.com/problems/climbing-stairs/)| [js](./algorithms/climbingStairs/climbingStairs.js), |Easy|
360360
|69|[Sqrt(x)](https://leetcode.com/problems/sqrtx/)| |Medium|
361361
|68|[Text Justification](https://leetcode.com/problems/text-justification/)| |Hard|
362-
|67|[Add Binary](https://leetcode.com/problems/add-binary/)| |Easy|
362+
|67|[Add Binary](https://leetcode.com/problems/add-binary/)| [java](./algorithms/addBinary/Solution.java) |Easy|
363363
|66|[Plus One](https://leetcode.com/problems/plus-one/)| |Easy|
364364
|65|[Valid Number](https://leetcode.com/problems/valid-number/)| |Easy|
365365
|64|[Minimum Path Sum](https://leetcode.com/problems/minimum-path-sum/)| |Medium|

algorithms/addBinary/Solution.java

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class Solution {
2+
// 偷懒算法,如果位过长,转化会溢出
3+
return Integer.toBinaryString(
4+
Integer.parseInt(a, 2) + Integer.parseInt(b, 2)
5+
);
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
public class Solution {
2+
public int titleToNumber(String s) {
3+
int result = 0;
4+
for(int i = 0; i<s.length();i++){
5+
int num = s.charAt(i) - 'A' + 1;
6+
result = result * 26 + num;
7+
}
8+
return result;
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public String convertToTitle(int n) {
3+
// 进制算法
4+
StringBuilder sb = new StringBuilder();
5+
while (n > 0) {
6+
int c = n % 26;
7+
if(c == 0){
8+
c = 26;
9+
n = n -1;
10+
}
11+
sb.insert(0, (char) ('A' + c - 1));
12+
n /= 26;
13+
}
14+
return sb.toString();
15+
}
16+
}

0 commit comments

Comments
 (0)