Skip to content

Commit 42a6d39

Browse files
committed
Added 2 solutions
1 parent f600d3d commit 42a6d39

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Easy/Nim Game.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Solution {
2+
public boolean canWinNim(int n) {
3+
return n % 4 != 0;
4+
}
5+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
public List<Integer> filterRestaurants(int[][] restaurants, int veganFriendly, int maxPrice, int maxDistance) {
3+
List<Integer> indexList = new ArrayList<>();
4+
for (int i = 0; i < restaurants.length; i++) {
5+
int[] restaurant = restaurants[i];
6+
if ((veganFriendly == 0 || restaurant[2] == 1) && restaurant[3] <= maxPrice && restaurant[4] <= maxDistance) {
7+
indexList.add(i);
8+
}
9+
}
10+
Collections.sort(indexList, new Comparator<Integer>() {
11+
public int compare(Integer o1, Integer o2) {
12+
int c = restaurants[o2][1] - restaurants[o1][1];
13+
if (c != 0) {
14+
return c;
15+
}
16+
return restaurants[o2][0] - restaurants[o1][0];
17+
}
18+
});
19+
List<Integer> ans = new ArrayList<>();
20+
for (Integer index : indexList) {
21+
ans.add(restaurants[index][0]);
22+
}
23+
return ans;
24+
}
25+
}

0 commit comments

Comments
 (0)