Created
December 3, 2020 21:28
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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