Skip to content

Instantly share code, notes, and snippets.

@R167
Last active August 29, 2015 14:15
Show Gist options
  • Save R167/dae493784e78b76441e9 to your computer and use it in GitHub Desktop.
Save R167/dae493784e78b76441e9 to your computer and use it in GitHub Desktop.
Coding Bats
// AP-1 => copyEndy
// passed
public int[] copyEndy(int[] nums, int count) {
int[] ret = new int[count];
int curr = 0;
for (int i = 0; i < nums.length && curr < count; i++) {
if ((nums[i] <= 10 && nums[i] >= 0) || (nums[i] <= 100 && nums[i] >= 90)) {
ret[curr] = nums[i];
curr += 1;
}
}
return ret;
}
// AP-1 => copyEvents
// passed
public int[] copyEvens(int[] nums, int count) {
int[] ret = new int[count];
int curr = 0;
for (int i = 0; curr < count && i < nums.length; i++) {
if (nums[i] % 2 == 0) {
ret[curr] = nums[i];
curr += 1;
}
}
return ret;
}
// AP-1 => matchUp
// passed
public int matchUp(String[] a, String[] b) {
int ret = 0;
for (int i = 0; i < a.length && i < b.length; i++) {
if (a[i].length() > 0 && b[i].length() > 0 && a[i].charAt(0) == b[i].charAt(0)) {
ret += 1;
}
}
return ret;
}
// AP-1 => scoresClump
// passed
public boolean scoresClump(int[] scores) {
for (int i = 0; i <= scores.length - 3; i++) {
if (scores[i + 2] - scores[i] <= 2) {
return true;
}
}
return false;
}
// AP-1 => userCompare
// passed
public int userCompare(String aName, int aId, String bName, int bId) {
int name = aName.compareTo(bName);
if (name < 0) {
return -1;
} else if (name > 0) {
return 1;
} else {
if (aId < bId) {
return -1;
} else if (aId > bId) {
return 1;
} else {
return 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment