mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-22 03:24:57 +08:00
style: enable NeedBraces
in checkstyle (#5227)
* enable style NeedBraces * style: enable NeedBraces in checkstyle --------- Co-authored-by: Samuel Facchinello <samuel.facchinello@piksel.com>
This commit is contained in:

committed by
GitHub

parent
51fcc66345
commit
87b17e0571
@ -18,7 +18,9 @@ public final class KadaneAlgorithm {
|
||||
// running sum of all the indexs are stored
|
||||
sum = Math.max(sum, runningSum);
|
||||
// the max is stored inorder to the get the maximum sum
|
||||
if (runningSum < 0) runningSum = 0;
|
||||
if (runningSum < 0) {
|
||||
runningSum = 0;
|
||||
}
|
||||
// if running sum is negative then it is initialized to zero
|
||||
}
|
||||
// for-each loop is used to iterate over the array and find the maximum subarray sum
|
||||
|
@ -69,19 +69,19 @@ public class OptimalJobScheduling {
|
||||
*/
|
||||
private int runningCost(int process, int machine) {
|
||||
|
||||
if (process == 0) // refers to the first process,which does not require for a previous one
|
||||
// to have been executed
|
||||
if (process == 0) { // refers to the first process,which does not require for a previous one
|
||||
// to have been executed
|
||||
return run[process][machine];
|
||||
else {
|
||||
} else {
|
||||
|
||||
int[] runningCosts = new int[numberMachines]; // stores the costs of executing our Process depending on
|
||||
// the Machine the previous one was executed
|
||||
// the Machine the previous one was executed
|
||||
|
||||
for (int k = 0; k < numberMachines; k++) // computes the cost of executing the previous
|
||||
// process to each and every Machine
|
||||
for (int k = 0; k < numberMachines; k++) { // computes the cost of executing the previous
|
||||
// process to each and every Machine
|
||||
runningCosts[k] = cost[process - 1][k] + transfer[k][machine] + run[process][machine]; // transferring the result to our Machine and executing
|
||||
// the Process to our Machine
|
||||
|
||||
// the Process to our Machine
|
||||
}
|
||||
return findMin(runningCosts); // returns the minimum running cost
|
||||
}
|
||||
}
|
||||
@ -98,7 +98,9 @@ public class OptimalJobScheduling {
|
||||
|
||||
for (int i = 1; i < costArr.length; i++) {
|
||||
|
||||
if (costArr[i] < costArr[min]) min = i;
|
||||
if (costArr[i] < costArr[min]) {
|
||||
min = i;
|
||||
}
|
||||
}
|
||||
return costArr[min];
|
||||
}
|
||||
|
@ -29,12 +29,16 @@ public final class SubsetCount {
|
||||
for (int i = 0; i < n; i++) {
|
||||
dp[i][0] = 1;
|
||||
}
|
||||
if (arr[0] <= target) dp[0][arr[0]] = 1;
|
||||
if (arr[0] <= target) {
|
||||
dp[0][arr[0]] = 1;
|
||||
}
|
||||
for (int t = 1; t <= target; t++) {
|
||||
for (int idx = 1; idx < n; idx++) {
|
||||
int notpick = dp[idx - 1][t];
|
||||
int pick = 0;
|
||||
if (arr[idx] <= t) pick += dp[idx - 1][target - t];
|
||||
if (arr[idx] <= t) {
|
||||
pick += dp[idx - 1][target - t];
|
||||
}
|
||||
dp[idx][target] = pick + notpick;
|
||||
}
|
||||
}
|
||||
@ -52,14 +56,18 @@ public final class SubsetCount {
|
||||
int n = arr.length;
|
||||
int[] prev = new int[target + 1];
|
||||
prev[0] = 1;
|
||||
if (arr[0] <= target) prev[arr[0]] = 1;
|
||||
if (arr[0] <= target) {
|
||||
prev[arr[0]] = 1;
|
||||
}
|
||||
for (int ind = 1; ind < n; ind++) {
|
||||
int[] cur = new int[target + 1];
|
||||
cur[0] = 1;
|
||||
for (int t = 1; t <= target; t++) {
|
||||
int notTaken = prev[t];
|
||||
int taken = 0;
|
||||
if (arr[ind] <= t) taken = prev[t - arr[ind]];
|
||||
if (arr[ind] <= t) {
|
||||
taken = prev[t - arr[ind]];
|
||||
}
|
||||
cur[t] = notTaken + taken;
|
||||
}
|
||||
prev = cur;
|
||||
|
@ -15,8 +15,12 @@ public final class Tribonacci {
|
||||
* @return the n-th Tribonacci number
|
||||
*/
|
||||
public static int compute(int n) {
|
||||
if (n == 0) return 0;
|
||||
if (n == 1 || n == 2) return 1;
|
||||
if (n == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (n == 1 || n == 2) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int first = 0;
|
||||
int second = 1;
|
||||
|
Reference in New Issue
Block a user