Skip to content

Commit e5052e4

Browse files
add 660
1 parent 1048fa5 commit e5052e4

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Your ideas/fixes/algorithms are more than welcome!
2222

2323
| # | Title | Solutions | Time | Space | Difficulty | Tag | Notes
2424
|-----|----------------|---------------|---------------|---------------|-------------|--------------|-----
25+
|660|[Remove 9](https://leetcode.com/problems/remove-9/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_660.java) | O(n) | O(1) | Hard | Math
2526
|659|[Split Array into Consecutive Subsequences](https://leetcode.com/problems/split-array-into-consecutive-subsequences/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_659.java) | O(n) | O(n) | Medium | HashMap
2627
|658|[Find K Closest Elements](https://leetcode.com/problems/find-k-closest-elements/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_658.java) | O(n) | O(1) | Medium |
2728
|657|[Judge Route Circle](https://leetcode.com/problems/judge-route-circle/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_657.java) | O(n) | O(1) | Easy |
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.fishercoder.solutions;
2+
3+
/**
4+
* 660. Remove 9
5+
*
6+
* Start from integer 1, remove any integer that contains 9 such as 9, 19, 29...
7+
8+
So now, you will have a new integer sequence: 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, ...
9+
10+
Given a positive integer n, you need to return the n-th integer after removing. Note that 1 will be the first integer.
11+
12+
Example 1:
13+
Input: 9
14+
Output: 10
15+
16+
Hint: n will not exceed 9 x 10^8.
17+
*/
18+
public class _660 {
19+
20+
public static class Solution1 {
21+
public int newInteger(int n) {
22+
return Integer.parseInt(Integer.toString(n, 9));
23+
}
24+
}
25+
26+
public static class Solution2 {
27+
public int newInteger(int n) {
28+
int result = 0;
29+
int base = 1;
30+
while (n > 0) {
31+
result += n % 9 * base;
32+
n /= 9;
33+
base *= 10;
34+
}
35+
return result;
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)