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

Commit 51c8c4a

Browse files
committed
biweekly-52
Signed-off-by: ashKIK <ashutheprogrammer@gmail.com>
1 parent 7e83f77 commit 51c8c4a

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
// https://leetcode.com/contest/biweekly-contest-52/problems/incremental-memory-leak/
3+
4+
public class IncrementalMemoryLeak {
5+
6+
public int[] memLeak(int memory1, int memory2) {
7+
int second;
8+
for (second = 1; memory1 >= second || memory2 >= second; second++) {
9+
if (memory2 > memory1) {
10+
memory2 -= second;
11+
} else {
12+
memory1 -= second;
13+
}
14+
}
15+
return new int[]{second, memory1, memory2};
16+
}
17+
}

‎biweekly-52/RotatingTheBox.java‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
// https://leetcode.com/contest/biweekly-contest-52/problems/rotating-the-box/
3+
4+
public class RotatingTheBox {
5+
6+
public char[][] rotateTheBox(char[][] box) {
7+
int m = box.length;
8+
int n = box[0].length;
9+
char[][] res = new char[n][m];
10+
for (int i = 0; i < m; i++) {
11+
int pos = n - 1;
12+
for (int j = n - 1; j >= 0; j--) {
13+
if (box[i][j] == '.') {
14+
res[j][m - i - 1] = '.';
15+
} else if (box[i][j] == '*') {
16+
res[j][m - i - 1] = '*';
17+
if (j > 0) {
18+
pos = j - 1;
19+
}
20+
} else {
21+
res[pos][m - i - 1] = '#';
22+
if (pos != j) {
23+
res[j][m - i - 1] = '.';
24+
}
25+
pos--;
26+
}
27+
}
28+
}
29+
return res;
30+
}
31+
}

‎biweekly-52/SortingTheSentence.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import java.util.Comparator;
33
import java.util.StringJoiner;
44

5+
// https://leetcode.com/contest/biweekly-contest-52/problems/sorting-the-sentence/
6+
57
public class SortingTheSentence {
68

79
public String sortSentence(String s) {

‎biweekly-52/SumOfFlooredPairs.java‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
// https://leetcode.com/contest/biweekly-contest-52/problems/sum-of-floored-pairs/
3+
4+
import java.util.Arrays;
5+
6+
public class SumOfFlooredPairs {
7+
8+
// sweep
9+
public int sumOfFlooredPairs(int[] nums) {
10+
int max = Arrays.stream(nums).max().orElse(-1);
11+
int[] vals = new int[max + 1];
12+
for (int num : nums) {
13+
vals[num]++;
14+
}
15+
for (int i = max; i > 0; i--) {
16+
for (int j = 2 * i; j <= max; j += i) {
17+
vals[j] += vals[i];
18+
}
19+
}
20+
for (int i = 1; i < vals.length; i++) {
21+
vals[i] += vals[i - 1];
22+
}
23+
int res = 0;
24+
for (int num : nums) {
25+
res = (res + vals[num]) % 1000000007;
26+
}
27+
return res;
28+
}
29+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /