Skip to content

Commit 70ab8cb

Browse files
committed
Added a < b comparison at the beginning as well
1 parent 682a74c commit 70ab8cb

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/main/java/main/java/videos/GCD.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ private static int iterativeGcd(int a, int b) {
2828
}
2929

3030
private static int binaryGcd(int a, int b) {
31+
if (a < b) {
32+
int tempSwap = a;
33+
a = b;
34+
b = tempSwap;
35+
}
36+
3137
if (b == 0) {
3238
return a;
3339
}

0 commit comments

Comments
 (0)