8000 [LEET-0000] add problem descriptions and clean up · aduispace/Leetcode-1@cd3ee74 · GitHub
[go: up one dir, main page]

Skip to content

Commit cd3ee74

Browse files
[LEET-0000] add problem descriptions and clean up
1 parent 74c7ae4 commit cd3ee74

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

leetcode-algorithms/src/main/java/com/stevesun/solutions/EliminationGame.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6+
/**There is a list of sorted integers from 1 to n. Starting from left to right, remove the first number and every other number afterward until you reach the end of the list.
7+
8+
Repeat the previous step again, but this time from right to left, remove the right most number and every other number from the remaining numbers.
9+
10+
We keep repeating the steps again, alternating left to right and right to left, until a single number remains.
11+
12+
Find the last number that remains starting with a list of length n.
13+
14+
Example:
15+
16+
Input:
17+
n = 9,
18+
1 2 3 4 5 6 7 8 9
19+
2 4 6 8
20+
2 6
21+
6
22+
23+
Output:
24+
6*/
625
public class EliminationGame {
726

827
//then I turned to Discuss and found this post: https://discuss.leetcode.com/topic/55870/share-my-solutions-for-contest-2

leetcode-algorithms/src/main/java/com/stevesun/solutions/IntegertoRoman.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package com.stevesun.solutions;
22

3-
public class IntegertoRoman {
4-
/**Given an integer, convert it to a roman numeral.
5-
6-
Input is guaranteed to be within the range from 1 to 3999.*/
3+
/**Given an integer, convert it to a roman numeral.
74
5+
Input is guaranteed to be within the range from 1 to 3999.*/
6+
public class IntegertoRoman {
87
//looked at this post: https://discuss.leetcode.com/topic/12384/simple-solution
98
public String intToRoman(int num) {
109
String M[] = {"", "M", "MM", "MMM"};

leetcode-algorithms/src/main/java/com/stevesun/solutions/IntersectionOfTwoArrays.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
import java.util.Iterator;
66
import java.util.Set;
77

8-
/**349. Intersection of Two Arrays QuestionEditorial Solution My Submissions
9-
Total Accepted: 37539
10-
Total Submissions: 84405
11-
Difficulty: Easy
8+
/**349. Intersection of Two Arrays
9+
*
1210
Given two arrays, write a function to compute their intersection.
1311
1412
Example:

leetcode-algorithms/src/main/java/com/stevesun/solutions/RotateFunction.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
package com.stevesun.solutions;
22

3+
/**Given an array of integers A and let n to be its length.
4+
5+
Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a "rotation function" F on A as follow:
6+
7+
F(k) = 0 * Bk[0] + 1 * Bk[1] + ... + (n-1) * Bk[n-1].
8+
9+
Calculate the maximum value of F(0), F(1), ..., F(n-1).
10+
11+
Note:
12+
n is guaranteed to be less than 105.
13+
14+
Example:
15+
16+
A = [4, 3, 2, 6]
17+
18+
F(0) = (0 * 4) + (1 * 3) + (2 * 2) + (3 * 6) = 0 + 3 + 4 + 18 = 25
19+
F(1) = (0 * 6) + (1 * 4) + (2 * 3) + (3 * 2) = 0 + 4 + 6 + 6 = 16
20+
F(2) = (0 * 2) + (1 * 6) + (2 * 4) + (3 * 3) = 0 + 6 + 8 + 9 = 23
21+
F(3) = (0 * 3) + (1 * 2) + (2 * 6) + (3 * 4) = 0 + 2 + 12 + 12 = 26
22+
23+
So the maximum value of F(0), F(1), F(2), F(3) is F(3) = 26.*/
324
//F(k) = 0 * Bk[0] + 1 * Bk[1] + ... + (n-1) * Bk[n-1]
425
public class RotateFunction {
526
public int maxRotateFunction(int[] A) {

0 commit comments

Comments
 (0)
0