qiqiatosu
BAN USER
Comments (4)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
public class Test{
public static void main(String args[]){
int[] a = {1,2,3,4,5,6};
int[] b = {-1,2,4,12,13,15};
int[] k = findK(a, b);
for(int c : k){
System.out.println(c + " ");
}
}
public static int[] findK(int[] a, int[] b)
{
if(a == null || b == null || a.length != b.length)
return null;
int[] result = new int[a.length];
int i = 1;
int j = 1;
for(int k = 1; k < result.length; k++){
int sumWithA = a[0] + b[j];
int sumWithB = b[0] + a[i];
if(sumWithA <= sumWithB){
result[k] = sumWithA;
j++;
}else{
result[k] = sumWithB;
i++;
}
}
return result;
}
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
I think there is a problem.
- qiqiatosu January 21, 2013for example: Strings are : axxxa, bxxxb, cxxxc
It can not form a cycle.