Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix code smells
  • Loading branch information
ThanhNIT committed Jan 1, 2022
commit 72c5416bdf8051e3c1e5c00e7476857825e7e857
4 changes: 3 additions & 1 deletion src/main/java/g0401_0500/s0500_keyboard_row/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
public class Solution {
private boolean check(String str, String word) {
for (char ch : word.toCharArray()) {
if (str.indexOf(ch) < 0) return false;
if (str.indexOf(ch) < 0) {
return false;
}
}
return true;
}
Expand Down
22 changes: 8 additions & 14 deletions src/main/java/g0501_0600/s0502_ipo/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@

// #Hard #Array #Sorting #Greedy #Heap_Priority_Queue

import java.util.Comparator;
import java.util.PriorityQueue;

public class Solution {
public int findMaximizedCapital(int k, int W, int[] profits, int[] capital) {
public int findMaximizedCapital(int k, int w, int[] profits, int[] capital) {
PriorityQueue<int[]> minCapital =
new PriorityQueue<>(
(int[] a, int[] b) -> {
return a[1] - b[1];
});
PriorityQueue<int[]> maxProfit =
new PriorityQueue<>(
(int[] a, int[] b) -> {
return b[0] - a[0];
});
new PriorityQueue<>(Comparator.comparingInt((int[] a) -> a[1]));
PriorityQueue<int[]> maxProfit = new PriorityQueue<>((int[] a, int[] b) -> b[0] - a[0]);
for (int i = 0; i < profits.length; i++) {
if (W >= capital[i]) {
if (w >= capital[i]) {
maxProfit.offer(new int[] {profits[i], capital[i]});
} else {
minCapital.offer(new int[] {profits[i], capital[i]});
Expand All @@ -26,12 +20,12 @@ public int findMaximizedCapital(int k, int W, int[] profits, int[] capital) {
int count = 0;
while (count < k && !maxProfit.isEmpty()) {
int[] temp = maxProfit.poll();
W += temp[0];
w += temp[0];
count += 1;
while (!minCapital.isEmpty() && minCapital.peek()[1] <= W) {
while (!minCapital.isEmpty() && minCapital.peek()[1] <= w) {
maxProfit.offer(minCapital.poll());
}
}
return W;
return w;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

// #Medium #Array #Stack #Monotonic_Stack

import java.util.Stack;
import java.util.ArrayDeque;
import java.util.Deque;

public class Solution {
// credit: https://leetcode.com/articles/next-greater-element-ii/
public int[] nextGreaterElements(int[] nums) {
int[] result = new int[nums.length];
Stack<Integer> stack = new Stack<>();
Deque<Integer> stack = new ArrayDeque<>();
for (int i = nums.length * 2 - 1; i >= 0; i--) {
while (!stack.isEmpty() && nums[stack.peek()] <= nums[i % nums.length]) {
stack.pop();
Expand Down