有人做hackranker的题么# JobHunting - 待字闺中
e*i
1 楼
不知道怎么写代码,求教:
比如题目是
Task
Complete the method insertionSort which takes in 1 parameter:
ar - an array with the value V in the right-most cell.
我不清楚如何写可以通过测试的code,主要是如何获取输入。网站上也没有个example.
比如我写的是
/* Head ends here */
import java.util.*;
public class Solution {
public void insertionSort(int[] ar) {
int lens = ar.length;
if(lens == 0){
return;
}
for(int i = 1; i < lens;i++){
for(int j = i; j > 0; j--){
if(ar[j] > ar[j-1]){
int temp = ar[j];
ar[j] = ar[j-1];
ar[j-1] = temp;
}
}
}
}
/* Tail starts here */
}
比如题目是
Task
Complete the method insertionSort which takes in 1 parameter:
ar - an array with the value V in the right-most cell.
我不清楚如何写可以通过测试的code,主要是如何获取输入。网站上也没有个example.
比如我写的是
/* Head ends here */
import java.util.*;
public class Solution {
public void insertionSort(int[] ar) {
int lens = ar.length;
if(lens == 0){
return;
}
for(int i = 1; i < lens;i++){
for(int j = i; j > 0; j--){
if(ar[j] > ar[j-1]){
int temp = ar[j];
ar[j] = ar[j-1];
ar[j-1] = temp;
}
}
}
}
/* Tail starts here */
}