Skip to content

Instantly share code, notes, and snippets.

@zeraf29
Created April 19, 2019 04:49
Show Gist options
  • Select an option

  • Save zeraf29/1f50e683e05b45171c8d4a4db2c267b3 to your computer and use it in GitHub Desktop.

Select an option

Save zeraf29/1f50e683e05b45171c8d4a4db2c267b3 to your computer and use it in GitHub Desktop.
// Comparing value at same index between List "a" and List "b"
import java.util.Arrays;
import java.util.List;
public class Solution {
// Comparing value at same index between List "a" and List "b"
static List<Integer> compareTriplets(List<Integer> a, List<Integer> b) {
//First. Using if condition
//if List "a"' value is bigger than List "b"
//, adding 1 point at List "resultList" 's index 0 value.
//else adding 1 point at List "resultList" 's index 1 value.
/*
List<Integer> resultList = new ArrayList<Integer>(){{add(0);add(0);}};
for(int i=0; i<a.size(); i++){
if(a.get(i)>b.get(i)) resultList.set(0,resultList.get(0)+1);
else if(a.get(i)<b.get(i)) resultList.set(1,resultList.get(1)+1);
}
return resultList;
*/
//Second, Using quotient and remainder
//if a's is bigger, adding size()+1.
//if b's is bigger, adding 1.
//when return it, a's score is quotient. b's score is remainder
//ex) a score 2, b score 3 --> 6+6+1+1+1 --> quotient=2, remainder=3
int result = 0;
for(int i=0; i<a.size(); i++){
result += (a.get(i)>=b.get(i))?((a.get(i)-b.get(i)>0)?(a.size()+1):0):1;
}
return Arrays.asList(result/(a.size()+1), result%(a.size()+1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment