LeetCode Contest 237
❤
1832. Check if the Sentence Is Pangram
https://leetcode.com/contest/weekly-contest-237/problems/check-if-the-sentence-is-pangram/
🐷 :
class Solution {
public boolean checkIfPangram(String sentence) {
if (sentence.equals("") || sentence.length() == 0) return false;
int[] nums = new int[26];
for (char c : sentence.toCharArray()) {
nums[c - 'a']--;
}
for (int num : nums) {
if (num == 0) return false;
}
return true;
}
}
🍀 :
1833. Maximum Ice Cream Bars
https://leetcode.com/contest/weekly-contest-237/problems/maximum-ice-cream-bars/
🐷 :
class Solution {
public int maxIceCream(int[] costs, int coins) {
if (costs == null || costs.length == 0 || coins == 0) return 0;
Arrays.sort(costs);
int res = 0;
for (int i = 0; i < costs.length; i++) {
if (costs[i] > coins || coins <= 0) return res;
coins -= costs[i];
res++;
}
return res;
}
}
🍀:
1834. Single-Threaded CPU
https://leetcode.com/contest/weekly-contest-237/problems/single-threaded-cpu/
🐷 :
class Solution {
public int[] getOrder(int[][] tasks) {
int n = tasks.length;
int[] res = new int[n];
int[][] extTasks = new int[n][3];
for(int i = 0; i < n; i++) {
extTasks[i][0] = i;
extTasks[i][1] = tasks[i][0];
extTasks[i][2] = tasks[i][1];
}
Arrays.sort(extTasks, (a, b) -> a[1] - b[1]);
PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> a[2] == b[2] ? a[0] - b[0] : a[2] - b[2]);
int time = 0;
int resIdx = 0;
int taskIdx = 0;
while(resIdx < n) {
while(taskIdx < n && extTasks[taskIdx][1] <= time) {
pq.offer(extTasks[taskIdx++]);
}
if(pq.isEmpty()) {
time = extTasks[taskIdx][1];
continue;
}
int[] bestFit = pq.poll();
res[resIdx++] = bestFit[0];
time += bestFit[2];
}
return res;
}
}
🍀 :
1835. Find XOR Sum of All Pairs Bitwise AND
https://leetcode.com/contest/weekly-contest-237/problems/find-xor-sum-of-all-pairs-bitwise-and/
🐷 :
class Solution {
public int getXORSum(int[] arr1, int[] arr2) {
int xora = 0, xorb = 0;
for (int a : arr1) xora ^= a;
for (int b : arr2) xorb ^= b;
return xora & xorb;
}
}
🍀: