This commit is contained in:
Kagura 2024-11-06 12:43:56 +08:00
parent bd736dff34
commit b580d1f644
2 changed files with 4 additions and 44 deletions

5
.gitignore vendored
View file

@ -26,4 +26,7 @@ bin/
.vscode/
### Mac OS ###
.DS_Store
.DS_Store
Main.kt
.idea/

View file

@ -1,43 +0,0 @@
package JavaDoubao;
import java.util.ArrayList;
public class XtoY {
public static class Main {
public static int solution(int xPosition, int yPosition) {
// Please write your code here
int diff = Math.abs(yPosition -xPosition);
int gone = 1;
ArrayList<Integer> steps = new ArrayList<>();
steps.add(1);
int lastStep = 1;
while (gone < diff/2) {
lastStep += 1;
gone += lastStep;
steps.add(lastStep);
}
if (gone*2 == diff){
}
for (Integer steps2 : steps) {
System.out.printf("%d,",steps2);
}
System.out.println("Result");
return steps.size();
}
public static void main(String[] args) {
// You can add more test cases here
// System.out.println(solution(12, 6));
System.out.println(solution(34, 45));
System.out.println(solution(50, 30));
}
}
}