top of page

Edabit Java: Positive Dominant, Hard Difficulty


solving this question in edabit: https://edabit.com/challenge/zi3zKpBL...​ using two array lists to see if the numbers are unique.


  • my answer is a bit janky but it is ok and gets the job done nicely!


Question:


Solution:



import java.util.ArrayList;


public class Dominance {

public static boolean isPositiveDominant(int[] n) {

int positiveCount = 0;

int negativeCount = 0;

ArrayList positives = new ArrayList(0);

ArrayList negatives = new ArrayList(0);

for(int i : n) {

if(i > 0) {

if(!positives.contains(i))

positiveCount++;

positives.add(i);

} else if(i < 0) {

if(!negatives.contains(i))

negativeCount++;

negatives.add(i);

}

}

return positiveCount > negativeCount;

}

}


14 views0 comments
Post: Blog2_Post
bottom of page