Skip to content

Commit 8a59777

Browse files
committed
Update
1 parent 99f9d7b commit 8a59777

6 files changed

+101
-4
lines changed

README.md

+7-4
Large diffs are not rendered by default.

my-submissions/m2225.java

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Solution {
2+
public List<List<Integer>> findWinners(int[][] matches) {
3+
HashMap<Integer, Integer> playerTracker = new HashMap<>();
4+
5+
for (int[] i : matches) {
6+
playerTracker.put(i[0], playerTracker.getOrDefault(i[0], 0)); // winner
7+
playerTracker.put(i[1], playerTracker.getOrDefault(i[1], 0) + 1); // loser
8+
}
9+
10+
List<Integer> noLoss = new ArrayList<>();
11+
List<Integer> oneLoss = new ArrayList<>();
12+
for (Integer player : playerTracker.keySet()) {
13+
if (playerTracker.get(player) == 0) {
14+
noLoss.add(player);
15+
} else if (playerTracker.get(player) == 1) {
16+
oneLoss.add(player);
17+
}
18+
}
19+
20+
Collections.sort(noLoss);
21+
Collections.sort(oneLoss);
22+
23+
ArrayList<List<Integer>> output = new ArrayList<>();
24+
output.add((List<Integer>) noLoss);
25+
output.add((List<Integer>) oneLoss);
26+
27+
return output;
28+
29+
30+
}
31+
}

my-submissions/m2545.java

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public int[][] sortTheStudents(int[][] score, int k) {
3+
Arrays.sort(score, new Comparator<int[]>() {
4+
public int compare(int[] a, int[] b) {
5+
return -1 * Integer.compare(a[k], b[k]);
6+
}
7+
});
8+
9+
return score;
10+
}
11+
}

my-submissions/m2545.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def sortTheStudents(self, score: List[List[int]], k: int) -> List[List[int]]:
3+
return sorted(score, key=lambda x: x[k], reverse=True)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public String customSortString(String order, String s) {
3+
HashMap<Character, Integer> reference = new HashMap<>();
4+
for (int i = 0; i < order.length(); i++) {
5+
reference.put(order.charAt(i), i);
6+
}
7+
8+
Character[] output = new Character[s.length()];
9+
for (int i = 0; i < s.length(); i++) {
10+
output[i] = s.charAt(i);
11+
}
12+
13+
Arrays.sort(output, (a, b) -> reference.getOrDefault(a, Integer.MAX_VALUE) - reference.getOrDefault(b, Integer.MAX_VALUE));
14+
15+
StringBuilder sb = new StringBuilder();
16+
17+
for (char c : output) {
18+
sb.append(c);
19+
}
20+
21+
return sb.toString();
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution {
2+
public String customSortString(String order, String s) {
3+
int[] charCounter = new int[26];
4+
5+
for (char c : s.toCharArray()) {
6+
charCounter[c - 'a']++;
7+
}
8+
9+
StringBuilder sb = new StringBuilder();
10+
for (char c : order.toCharArray()) {
11+
for (int i = 0; i < charCounter[c - 'a']; i++) {
12+
sb.append(c);
13+
}
14+
charCounter[c - 'a'] = 0;
15+
}
16+
17+
for (int i = 0; i < charCounter.length; i++) {
18+
while (charCounter[i] > 0) {
19+
sb.append((char) ('a' + i));
20+
charCounter[i]--;
21+
}
22+
}
23+
24+
return sb.toString();
25+
}
26+
}

0 commit comments

Comments
 (0)