Skip to content

Instantly share code, notes, and snippets.

@kingsamadesu
Created December 3, 2020 21:28
Show Gist options
  • Save kingsamadesu/0b20a98a3b93ab0c5c2f9e4d2df7e059 to your computer and use it in GitHub Desktop.
Save kingsamadesu/0b20a98a3b93ab0c5c2f9e4d2df7e059 to your computer and use it in GitHub Desktop.
1217. Minimum Cost to Move Chips to The Same Position -with java- (leetcode.com)
/*
Your memory usage beats 74.60 % of java submissions.
*/
class Solution {
public int min(int a, int b){
if (a<b){
return a;
}
return b;
}
public int minCostToMoveChips(int[] position) {
int[] counter = {0,0};
for( int i = 0 ; i < position.length ; i++){
if(position[i]%2==0){
counter[1]++;
}
else{
counter[0]++;
}
}
return min(counter[0],counter[1]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment