Skip to content

Commit

Permalink
Fixed idea warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
javadev authored Oct 8, 2024
1 parent 7cdd22d commit 3d5f668
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@SuppressWarnings("java:S1104")
public class Trie {
private TrieNode root;
private final TrieNode root;
private boolean startWith;

private static class TrieNode {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* }
*/
public class Solution {
interface Master {
public interface Master {
int guess(String word);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package g1001_1100.s1095_find_in_mountain_array;

interface MountainArray {
public interface MountainArray {
int get(int index);

int length();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ public int minCostConnectPoints(int[][] points) {
return cost;
}

public void constructMST(
private void constructMST(
int[] parent, int[][] points, boolean[] mst, PriorityQueue<Pair> 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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Integer> queue = new LinkedList<>();
queue.add(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 3d5f668

Please sign in to comment.