From 3d5f668371b87ff29d05889f18746b9f050fa7bf Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Tue, 8 Oct 2024 12:27:55 +0300 Subject: [PATCH] Fixed idea warnings --- .../g0201_0300/s0208_implement_trie_prefix_tree/Trie.java | 4 ++-- .../g0401_0500/s0432_all_oone_data_structure/AllOne.java | 4 ++-- .../java/g0801_0900/s0843_guess_the_word/Solution.java | 2 +- .../s1095_find_in_mountain_array/MountainArray.java | 2 +- .../s1191_k_concatenation_maximum_sum/Solution.java | 8 ++++---- .../s1584_min_cost_to_connect_all_points/Solution.java | 3 ++- .../Solution.java | 8 ++++---- .../s2502_design_memory_allocator/Allocator.java | 4 ++-- .../s2612_minimum_reverse_operations/Solution.java | 5 ++--- .../Solution.java | 5 ++--- .../s3210_find_the_encrypted_string/Solution.java | 6 ++---- 11 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/main/java/g0201_0300/s0208_implement_trie_prefix_tree/Trie.java b/src/main/java/g0201_0300/s0208_implement_trie_prefix_tree/Trie.java index 206a88b36..c8ccd56fc 100644 --- a/src/main/java/g0201_0300/s0208_implement_trie_prefix_tree/Trie.java +++ b/src/main/java/g0201_0300/s0208_implement_trie_prefix_tree/Trie.java @@ -7,7 +7,7 @@ @SuppressWarnings("java:S1104") public class Trie { - private TrieNode root; + private final TrieNode root; private boolean startWith; private static class TrieNode { @@ -46,7 +46,7 @@ public boolean search(String word) { return search(word, root, 0); } - public boolean search(String word, TrieNode root, int idx) { + private boolean search(String word, TrieNode root, int idx) { if (idx == word.length()) { startWith = true; return root.isWord; diff --git a/src/main/java/g0401_0500/s0432_all_oone_data_structure/AllOne.java b/src/main/java/g0401_0500/s0432_all_oone_data_structure/AllOne.java index 873600905..aa7487154 100644 --- a/src/main/java/g0401_0500/s0432_all_oone_data_structure/AllOne.java +++ b/src/main/java/g0401_0500/s0432_all_oone_data_structure/AllOne.java @@ -69,12 +69,12 @@ public void dec(String key) { /* Returns one of the keys with maximal value. */ public String getMaxKey() { - return tail.pre == head ? "" : (String) tail.pre.keySet.iterator().next(); + return tail.pre == head ? "" : tail.pre.keySet.iterator().next(); } /* Returns one of the keys with Minimal value. */ public String getMinKey() { - return head.next == tail ? "" : (String) head.next.keySet.iterator().next(); + return head.next == tail ? "" : head.next.keySet.iterator().next(); } // helper function to make change on given key according to offset diff --git a/src/main/java/g0801_0900/s0843_guess_the_word/Solution.java b/src/main/java/g0801_0900/s0843_guess_the_word/Solution.java index b7c31b09d..87faebfa2 100644 --- a/src/main/java/g0801_0900/s0843_guess_the_word/Solution.java +++ b/src/main/java/g0801_0900/s0843_guess_the_word/Solution.java @@ -15,7 +15,7 @@ * } */ public class Solution { - interface Master { + public interface Master { int guess(String word); } diff --git a/src/main/java/g1001_1100/s1095_find_in_mountain_array/MountainArray.java b/src/main/java/g1001_1100/s1095_find_in_mountain_array/MountainArray.java index 448036bf0..9fea6a156 100644 --- a/src/main/java/g1001_1100/s1095_find_in_mountain_array/MountainArray.java +++ b/src/main/java/g1001_1100/s1095_find_in_mountain_array/MountainArray.java @@ -1,6 +1,6 @@ package g1001_1100.s1095_find_in_mountain_array; -interface MountainArray { +public interface MountainArray { int get(int index); int length(); diff --git a/src/main/java/g1101_1200/s1191_k_concatenation_maximum_sum/Solution.java b/src/main/java/g1101_1200/s1191_k_concatenation_maximum_sum/Solution.java index 6d28b4dec..4c51832e2 100644 --- a/src/main/java/g1101_1200/s1191_k_concatenation_maximum_sum/Solution.java +++ b/src/main/java/g1101_1200/s1191_k_concatenation_maximum_sum/Solution.java @@ -3,13 +3,13 @@ // #Medium #Array #Dynamic_Programming #2022_03_03_Time_6_ms_(73.85%)_Space_59.8_MB_(30.38%) public class Solution { - private long mod = 1000000007; + private static final long MOD = 1000000007; public int kConcatenationMaxSum(int[] arr, int k) { // int kadane = Kadane(arr); // #1 when k 1 simply calculate kadanes if (k == 1) { - return (int) (kadane(arr) % mod); + return (int) (kadane(arr) % MOD); } // #2 else calculate the total sum and then check if sum is -Ve or +Ve long totalSum = 0; @@ -19,11 +19,11 @@ public int kConcatenationMaxSum(int[] arr, int k) { // #3 when negative then calculate of arr 2 times only the answer is in there only if (totalSum < 0) { // when -ve sum put a extra check here of max from 0 - return (int) Math.max(kadaneTwo(arr) % mod, 0); + return (int) Math.max(kadaneTwo(arr) % MOD, 0); } else { // #4 when sum is positve then the ans is kadane of 2 + sum * (k-2); // these two are used sUm*(k-2) ensures that all other are also included - return (int) ((kadaneTwo(arr) + ((k - 2) * totalSum) + mod) % mod); + return (int) ((kadaneTwo(arr) + ((k - 2) * totalSum) + MOD) % MOD); } } diff --git a/src/main/java/g1501_1600/s1584_min_cost_to_connect_all_points/Solution.java b/src/main/java/g1501_1600/s1584_min_cost_to_connect_all_points/Solution.java index 0ae0a15b7..a066f07c8 100644 --- a/src/main/java/g1501_1600/s1584_min_cost_to_connect_all_points/Solution.java +++ b/src/main/java/g1501_1600/s1584_min_cost_to_connect_all_points/Solution.java @@ -32,12 +32,13 @@ public int minCostConnectPoints(int[][] points) { return cost; } - public void constructMST( + private void constructMST( int[] parent, int[][] points, boolean[] mst, PriorityQueue pq, int[] dist) { if (!containsFalse(mst)) { return; } Pair newPair = pq.poll(); + assert newPair != null; int pointIndex = newPair.getV(); mst[pointIndex] = true; for (int i = 0; i < parent.length; i++) { diff --git a/src/main/java/g2301_2400/s2400_number_of_ways_to_reach_a_position_after_exactly_k_steps/Solution.java b/src/main/java/g2301_2400/s2400_number_of_ways_to_reach_a_position_after_exactly_k_steps/Solution.java index 4ccdd77ef..746708d05 100644 --- a/src/main/java/g2301_2400/s2400_number_of_ways_to_reach_a_position_after_exactly_k_steps/Solution.java +++ b/src/main/java/g2301_2400/s2400_number_of_ways_to_reach_a_position_after_exactly_k_steps/Solution.java @@ -4,7 +4,7 @@ // #2022_09_19_Time_1_ms_(99.66%)_Space_41.7_MB_(91.83%) public class Solution { - private int mod = 1000000007; + private static final int MOD = 1000000007; public int numberOfWays(int startPos, int endPos, int k) { if (Math.abs(endPos - startPos) > k) { @@ -23,9 +23,9 @@ public int numberOfWays(int startPos, int endPos, int k) { rev[1] = 1; int ans = k; for (int i = 2; i <= min; i++) { - rev[i] = (int) ((long) (mod - mod / i) * (long) rev[mod % i] % mod); - ans = (int) ((long) ans * (long) (k - i + 1) % mod); - ans = (int) ((long) ans * (long) rev[i] % mod); + rev[i] = (int) ((long) (MOD - MOD / i) * (long) rev[MOD % i] % MOD); + ans = (int) ((long) ans * (long) (k - i + 1) % MOD); + ans = (int) ((long) ans * (long) rev[i] % MOD); } return ans; } diff --git a/src/main/java/g2501_2600/s2502_design_memory_allocator/Allocator.java b/src/main/java/g2501_2600/s2502_design_memory_allocator/Allocator.java index 5af33bfab..9a71e6ac6 100644 --- a/src/main/java/g2501_2600/s2502_design_memory_allocator/Allocator.java +++ b/src/main/java/g2501_2600/s2502_design_memory_allocator/Allocator.java @@ -4,7 +4,7 @@ // #2023_03_19_Time_9_ms_(100.00%)_Space_43_MB_(66.82%) public class Allocator { - Node root; + private final Node root; public Allocator(int n) { root = new Node(0, n, -1); @@ -36,7 +36,7 @@ public int free(int mID) { return collapse(root, mID); } - public int collapse(Node cur, int id) { + private int collapse(Node cur, int id) { // base case if (cur == null) { return 0; diff --git a/src/main/java/g2601_2700/s2612_minimum_reverse_operations/Solution.java b/src/main/java/g2601_2700/s2612_minimum_reverse_operations/Solution.java index df22d64da..684618448 100644 --- a/src/main/java/g2601_2700/s2612_minimum_reverse_operations/Solution.java +++ b/src/main/java/g2601_2700/s2612_minimum_reverse_operations/Solution.java @@ -4,14 +4,13 @@ // #2023_08_30_Time_19_ms_(100.00%)_Space_59_MB_(78.00%) import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class Solution { public int[] minReverseOperations(int n, int p, int[] banned, int k) { int[] out = new int[n]; - for (int i = 0; i < n; i++) { - out[i] = -1; - } + Arrays.fill(out, -1); for (int node : banned) { out[node] = -2; } diff --git a/src/main/java/g2801_2900/s2858_minimum_edge_reversals_so_every_node_is_reachable/Solution.java b/src/main/java/g2801_2900/s2858_minimum_edge_reversals_so_every_node_is_reachable/Solution.java index db4db0a27..62a8bb891 100644 --- a/src/main/java/g2801_2900/s2858_minimum_edge_reversals_so_every_node_is_reachable/Solution.java +++ b/src/main/java/g2801_2900/s2858_minimum_edge_reversals_so_every_node_is_reachable/Solution.java @@ -4,6 +4,7 @@ // #2023_12_19_Time_52_ms_(92.31%)_Space_119.5_MB_(75.38%) import java.util.ArrayList; +import java.util.Arrays; import java.util.LinkedList; import java.util.List; import java.util.Queue; @@ -22,9 +23,7 @@ public int[] minEdgeReversals(int n, int[][] edges) { nexts[v].add(new int[] {-1, u}); } int[] res = new int[n]; - for (int i = 0; i < n; i++) { - res[i] = -1; - } + Arrays.fill(res, -1); res[0] = dfs(nexts, 0, -1); Queue queue = new LinkedList<>(); queue.add(0); diff --git a/src/main/java/g3201_3300/s3210_find_the_encrypted_string/Solution.java b/src/main/java/g3201_3300/s3210_find_the_encrypted_string/Solution.java index 92abd65b9..29f50ba73 100644 --- a/src/main/java/g3201_3300/s3210_find_the_encrypted_string/Solution.java +++ b/src/main/java/g3201_3300/s3210_find_the_encrypted_string/Solution.java @@ -5,9 +5,7 @@ public class Solution { public String getEncryptedString(String s, int k) { int n = s.length(); - k = k % n; - StringBuilder str = new StringBuilder(s.substring(k, n)); - str.append(s.substring(0, k)); - return str.toString(); + int localK = k % n; + return s.substring(localK, n) + s.substring(0, localK); } }