start1([1, 2, 3], [1, 3]) → 2
start1([7, 2, 3], [1]) → 1
start1([1, 2], []) → 1
Answer 1:
public int start1(int[] a, int[] b) {
int sum = 0;
if(a.length>0 && a[0] == 1) sum++;
if(b.length>0 && b[0] == 1) sum++;
return sum;
}
Answer 2:
public int start1(int[] a, int[] b) {
int count = 0;
if (a.length != 0) {
if (a[0]== 1) count++; }
if (b.length != 0) {
if (b[0]== 1) count++; }
return count;
}
No comments :
Post a Comment