Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7f1a1c9

Browse files
clean up Contest package
1 parenta4a87e7 commit7f1a1c9

File tree

4 files changed

+10
-37
lines changed

4 files changed

+10
-37
lines changed

‎Contest/src/_20160910_4th_contest/IntegerReplacement.javarenamed to‎EASY/src/easy/IntegerReplacement.java

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,8 @@
1-
package_20160910_4th_contest;
1+
packageeasy;
22

3-
importjava.util.HashSet;
4-
importjava.util.Iterator;
5-
importjava.util.LinkedList;
6-
importjava.util.Queue;
7-
importjava.util.Set;
3+
importjava.util.*;
84

95
publicclassIntegerReplacement {
10-
publicstaticintintegerReplacement_failed(intn) {
11-
if(n ==1)return0;
12-
intsteps =0;
13-
while(n !=1){
14-
if(n%2 ==1 &&n >1) {
15-
n -=1;
16-
steps++;
17-
}
18-
19-
n /=2;
20-
steps++;
21-
}
22-
returnsteps;
23-
}
24-
25-
publicstaticintintegerReplacement_failed_2(intn) {
26-
if(n ==1)return0;
27-
inttemp =2,steps =1;
28-
while(temp <=n){
29-
temp *=2;
30-
steps++;
31-
32-
if(temp%2 ==1){
33-
temp +=1;
34-
steps++;
35-
}
36-
}
37-
returnsteps;
38-
}
396

407
publicstaticintintegerReplacement(intn) {
418
longmin =Long.MAX_VALUE;

‎Contest/src/_20160910_4th_contest/RotateFunction.javarenamed to‎EASY/src/easy/RotateFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package_20160910_4th_contest;
1+
packageeasy;
22

33
//F(k) = 0 * Bk[0] + 1 * Bk[1] + ... + (n-1) * Bk[n-1]
44
publicclassRotateFunction {

‎Contest/src/_20160910_4th_contest/RandomPickIndex.javarenamed to‎MEDIUM/RandomPickIndex.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ public class RandomPickIndex {
99

1010
}
1111

12+
//TODO: use reservoir sampling to solve it again
13+
1214
classSolution {
15+
//brute force
1316
int[]input;
1417
java.util.Randomrand =newjava.util.Random();
1518
publicSolution(int[]nums) {
@@ -30,7 +33,7 @@ public int pick(int target) {
3033
}
3134

3235

33-
classSolution_MLE {
36+
classSolution_MemoryLimitExceeded {
3437

3538
privateMap<Integer,List<Integer>>map =newHashMap();
3639
java.util.Randomrand =newjava.util.Random();

‎README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
| # | Title | Solutions | Time | Space | Difficulty | Tag | Notes
33
|-----|----------------|---------------|---------------|---------------|-------------|--------------|-----
44
|415|[Add Strings](https://leetcode.com/problems/add-strings/)|[Solution](../../blob/master/EASY/src/easy/AddStrings.java)| O(n)|O(1)| Easy|
5+
|398|[Random Pick Index](https://leetcode.com/problems/random-pick-index/)|[Solution](../../blob/master/MEDIUM/src/medium/RandomPickIndex.java)| | | Medium| Reservoir Sampling
6+
|397|[Integer Replacement](https://leetcode.com/problems/integer-replacement/)|[Solution](../../blob/master/EASY/src/easy/IntegerReplacement.java)| ? | ? | Easy| BFS
7+
|396|[Rotate Function](https://leetcode.com/problems/rotate-function/)|[Solution](../../blob/master/EASY/src/easy/RotateFunction.java)| O(n^2) could be optimized to O(n)| O(1)| Easy|
58
|390|[Elimination Game](https://leetcode.com/problems/elimination-game/)|[Solution](../../blob/master/MEDIUM/src/medium/EliminationGame.java)| O(logn)|O(1)| Medium|
69
|389|[Find the Difference](https://leetcode.com/problems/find-the-difference/)|[Solution](../../blob/master/EASY/src/easy/FindTheDifference.java)| O(n)|O(1)| Easy|
710
|388|[Longest Absolute File Path](https://leetcode.com/problems/longest-absolute-file-path/)|[Solution](../../blob/master/MEDIUM/src/medium/LongestAbsoluteFilePath.java)| O(n)|O(d) | Medium| Stack

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp