Skip to content

Commit 818ed59

Browse files
authored
Fixed idea warnings
1 parent 113ad95 commit 818ed59

File tree

27 files changed

+70
-63
lines changed

27 files changed

+70
-63
lines changed

src/main/java/g0201_0300/s0282_expression_add_operators/Solution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
public class Solution {
1010
public List<String> addOperators(String num, int target) {
1111
List<String> res = new ArrayList<>();
12-
if (num.length() == 0 || Long.valueOf(num) > Integer.MAX_VALUE) {
12+
if (num.length() == 0 || Long.parseLong(num) > Integer.MAX_VALUE) {
1313
return res;
1414
}
1515
char[] list = num.toCharArray();

src/main/java/g0301_0400/s0400_nth_digit/Solution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public int findNthDigit(int n) {
1313
long count = 9;
1414
int start = 1;
1515
while (n > len * count) {
16-
n -= len * count;
16+
n -= (int) (len * count);
1717
len += 1;
1818
count *= 10;
1919
start *= 10;

src/main/java/g0401_0500/s0419_battleships_in_a_board/Solution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public int countBattleships(char[][] board) {
1313
for (int i = 0; i < m; i++) {
1414
for (int j = 0; j < n; j++) {
1515
if (board[i][j] != '.'
16-
&& (j <= 0 || board[i][j - 1] != 'X')
16+
&& (j == 0 || board[i][j - 1] != 'X')
1717
&& (i <= 0 || board[i - 1][j] != 'X')) {
1818
count++;
1919
}

src/main/java/g0801_0900/s0880_decoded_string_at_index/Solution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public String decodeAtIndex(String s, int k) {
1515
}
1616
for (int i = s.length() - 1; i >= 0; i--) {
1717
char c = s.charAt(i);
18-
k %= length;
18+
k %= (int) length;
1919
if (c >= 48 && c <= 57) {
2020
length /= c - '0';
2121
} else if (k == 0) {

src/main/java/g1001_1100/s1009_complement_of_base_10_integer/Solution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public int bitwiseComplement(int n) {
2020
int exp = list.size() - 1;
2121
for (int i = list.size() - 1; i >= 0; i--) {
2222
if (list.get(i) == 0) {
23-
result += Math.pow(2, exp);
23+
result += (int) Math.pow(2, exp);
2424
}
2525
exp--;
2626
}

src/main/java/g1101_1200/s1195_fizz_buzz_multithreaded/FizzBuzz.java

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,75 @@
11
package g1101_1200.s1195_fizz_buzz_multithreaded;
22

3-
// #Medium #Concurrency #2022_03_03_Time_8_ms_(80.09%)_Space_43.2_MB_(6.17%)
3+
// #Medium #Concurrency #2024_11_24_Time_6_ms_(94.88%)_Space_43.1_MB_(8.61%)
44

5-
import java.util.concurrent.atomic.AtomicInteger;
65
import java.util.function.IntConsumer;
76

87
@SuppressWarnings("java:S1130")
98
public class FizzBuzz {
10-
private final AtomicInteger count = new AtomicInteger(1);
11-
129
private final int n;
10+
private int current;
1311

1412
public FizzBuzz(int n) {
1513
this.n = n;
14+
this.current = 1;
1615
}
1716

1817
// printFizz.run() outputs "fizz".
1918
public void fizz(Runnable printFizz) throws InterruptedException {
20-
int i;
21-
while ((i = count.get()) <= n) {
22-
if (i % 3 == 0 && i % 5 != 0) {
23-
printFizz.run();
24-
count.compareAndSet(i, i + 1);
19+
synchronized (this) {
20+
while (current <= n) {
21+
if (current % 3 == 0 && current % 5 != 0) {
22+
printFizz.run();
23+
current += 1;
24+
notifyAll();
25+
} else {
26+
wait();
27+
}
2528
}
2629
}
2730
}
2831

2932
// printBuzz.run() outputs "buzz".
3033
public void buzz(Runnable printBuzz) throws InterruptedException {
31-
int i;
32-
while ((i = count.get()) <= n) {
33-
count.get();
34-
if (i % 5 == 0 && i % 3 != 0) {
35-
printBuzz.run();
36-
count.compareAndSet(i, i + 1);
34+
synchronized (this) {
35+
while (current <= n) {
36+
if (current % 3 != 0 && current % 5 == 0) {
37+
printBuzz.run();
38+
current += 1;
39+
notifyAll();
40+
} else {
41+
wait();
42+
}
3743
}
3844
}
3945
}
4046

4147
// printFizzBuzz.run() outputs "fizzbuzz".
4248
public void fizzbuzz(Runnable printFizzBuzz) throws InterruptedException {
43-
int i;
44-
while ((i = count.get()) <= n) {
45-
if (i % 15 == 0) {
46-
printFizzBuzz.run();
47-
count.compareAndSet(i, i + 1);
49+
synchronized (this) {
50+
while (current <= n) {
51+
if (current % 15 == 0) {
52+
printFizzBuzz.run();
53+
current += 1;
54+
notifyAll();
55+
} else {
56+
wait();
57+
}
4858
}
4959
}
5060
}
5161

5262
// printNumber.accept(x) outputs "x", where x is an integer.
5363
public void number(IntConsumer printNumber) throws InterruptedException {
54-
int i;
55-
while ((i = count.get()) <= n) {
56-
if (i % 5 != 0 && i % 3 != 0) {
57-
printNumber.accept(i);
58-
count.compareAndSet(i, i + 1);
64+
synchronized (this) {
65+
while (current <= n) {
66+
if (current % 3 != 0 && current % 5 != 0) {
67+
printNumber.accept(current);
68+
current += 1;
69+
notifyAll();
70+
} else {
71+
wait();
72+
}
5973
}
6074
}
6175
}

src/main/java/g1201_1300/s1286_iterator_for_combination/CombinationIterator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ public class CombinationIterator {
1010
private List<String> list;
1111
private int index;
1212
private int combinationLength;
13-
private boolean[] visited;
1413

1514
public CombinationIterator(String characters, int combinationLength) {
1615
this.index = 0;
1716
this.list = new ArrayList<>();
1817
this.combinationLength = combinationLength;
19-
this.visited = new boolean[characters.length()];
18+
boolean[] visited = new boolean[characters.length()];
2019
buildAllCombinations(characters, 0, new StringBuilder(), visited);
2120
}
2221

src/main/java/g1301_1400/s1354_construct_target_array_with_multiple_sums/Solution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public boolean isPossible(int[] target) {
2121
|| target[maxIndex] % remainingSum == 0) {
2222
return false;
2323
}
24-
target[maxIndex] %= remainingSum;
24+
target[maxIndex] %= (int) remainingSum;
2525
return isPossible(target);
2626
}
2727
}

src/main/java/g1501_1600/s1519_number_of_nodes_in_the_sub_tree_with_the_same_label/Solution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public class Solution {
99
public int[] countSubTrees(int n, int[][] edges, String labelsString) {
1010
int[] labelsCount = new int[n];
11-
if (n <= 0 || edges == null || labelsString == null) {
11+
if (n == 0 || edges == null || labelsString == null) {
1212
return labelsCount;
1313
}
1414

src/main/java/g1601_1700/s1648_sell_diminishing_valued_colored_balls/Solution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public int maxProfit(int[] inventory, int orders) {
1818
long diff = i == 0 ? inventory[i] : inventory[i] - inventory[i - 1];
1919
if (count * diff < orders) {
2020
totalValue += (2L * inventory[i] - diff + 1) * diff * count / 2 % mod;
21-
orders -= count * diff;
21+
orders -= (int) (count * diff);
2222
} else {
2323
diff = orders / count;
2424
long remainder = orders % count;

0 commit comments

Comments
 (0)