You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Solution {
public int minCostToMoveChips(int[] position) {
int even = 0;
int odd = 0;
for(int i : position) {
if(i % 2 == 0) even++;
else odd++;
}
return Math.min(even, odd);
}
}
This solution is much easier to understand. Actually i am learning and building my skills for open source so please assign me this issue to help me grow !
class Solution {
public int minCostToMoveChips(int[] position) {
int num=0;
for(int i: position){
num+=i%2;
}
return Math.min(num, position.length-num);
}
}
Here I am trying to count odd elements, get its complement for even elements, and do Math. min on those.
Activity
NeuYash commentedon Jul 12, 2024
class Solution {
public int minCostToMoveChips(int[] position) {
int num=0;
for(int i: position){
num+=i%2;
}
return Math.min(num, position.length-num);
}
Here I am trying to count odd elements, get its complement for even elements, and do Math. min on those.