codingChallenge
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
*
|
||||
* Alone
|
||||
*/
|
||||
public class Alone {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int[] arr = { 1, 1, 1, 3, 4, 4, 5, 5, 5, 5 };
|
||||
System.out.println(lonelyNum(arr));
|
||||
}
|
||||
|
||||
public static int lonelyNum(int[] nums) {
|
||||
int count = 0;
|
||||
nums[0] = 0;
|
||||
for (int x : nums) {
|
||||
for (int i = 0; i < nums.length; i++) {
|
||||
if (x != nums[i]) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
*
|
||||
* Alone
|
||||
*/
|
||||
public class Alonea {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int[] arr = { 1, 1, 1, 3, 4, 4, 5, 5, 5, 5 };
|
||||
System.out.println(lonelyNum(arr));
|
||||
}
|
||||
|
||||
public static int lonelyNum(int[] nums) {
|
||||
int count = 0;
|
||||
int i = nums.length;
|
||||
for (int x : nums) {
|
||||
if (x == nums[i]) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user