Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- public static String solution(String x, String y) {
- String cycles = minCycles(1, 1, Integer.valueOf(x), Integer.valueOf(y));
- if(cycles == null)
- return "impossible";
- else
- return cycles;
- }
- public static String minCycles(int x, int y, int m, int f){
- if(x == m && y == f) {
- return "0";
- }
- if(x > m || y > f)
- return null;
- String result1 = minCycles(x, x+y, m, f);
- String result2 = minCycles(x+y, y, m, f);
- if (result1 == null && result2 == null) {
- return null;
- } else if (result1 == null || result2 == null) {
- if(result1 == null) {
- int a = Integer.valueOf(result2);
- return String.valueOf(++a);
- }
- else {
- int b = Integer.valueOf(result1);
- return String.valueOf(++b);
- }
- } else {
- int a = Integer.valueOf(result1);
- int b = Integer.valueOf(result2);
- int c = Math.min(a, b);
- return String.valueOf(++c);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement