Skip to content

Commit e1d5ecf

Browse files
author
github-actions
committed
Format - Google java formatter
1 parent fc30b38 commit e1d5ecf

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Recursion/JosephusProblem/Solution.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
/**
77
* * Josephus Problem
88
*/
9-
109
public class Solution {
1110
private int solveJosephusProblem(List<Integer> soldiers, int k, int index) {
1211
/**
1312
* Base Case.
1413
*/
15-
if (soldiers.size() == 1)
16-
return soldiers.get(0);
14+
if (soldiers.size() == 1) return soldiers.get(0);
1715

1816
int killIdx = (index + k) % soldiers.size();
1917
soldiers.remove(killIdx);
@@ -24,8 +22,7 @@ private int solveJosephusProblem(List<Integer> soldiers, int k, int index) {
2422
public int solveJosephusProblem(int n, int k) {
2523
List<Integer> soldiers = new ArrayList<>();
2624

27-
for (int idx = 1; idx <= n; idx++)
28-
soldiers.add(idx);
25+
for (int idx = 1; idx <= n; idx++) soldiers.add(idx);
2926

3027
return solveJosephusProblem(soldiers, k - 1, 0);
3128
}
@@ -35,4 +32,4 @@ public static void main(String[] args) {
3532

3633
System.out.println(solution.solveJosephusProblem(14, 2));
3734
}
38-
}
35+
}

0 commit comments

Comments
 (0)