[LeetCode] #1217. Play with Chips

Input: chips = [1,2,3]
Output: 1
Explanation: Second chip will be moved to positon 3 with cost 1. First chip will be moved to position 3 with cost 0. Total cost is 1.
Input: chips = [2,2,2,3,3]
Output: 2
Explanation: Both fourth and fifth chip will be moved to position two with cost 1. Total minimum cost will be 2.
class Solution:
def minCostToMoveChips(self, chips: List[int]) -> int:
O=0
E=0
for x in chips:
if x % 2 == 0:
E += 1
else:
O += 1
return min(E, O)

--

--

--

Interesting in any computer science.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

HTTP Error Code Caching with CloudFront (CDNs)

Transferring an Existing Software Product to a New Team — a Checklist

Exploring Microsoft Graph Toolkit Lap as a non-developer — Part 2

How To Merge Other Git Branches Into Your Own

Branches

A Swift Tour(Review of Basic Syntax)

AWS AUDITING, MONITORING AND NOTIFICATION SERVICES

Core Challenge 4: Create a negative pickup

What is Recursion?!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fatboy Slim

Fatboy Slim

Interesting in any computer science.

More from Medium

Leetcode Python 刷題記錄 Day 1

LeetCode #3 | Longest Substring Without Repeating Characters (Python)

LeetCode Patterns Adventure 16 — Merge Two Sorted Lists

3sum Closest Leetcode Solution — Leetcode Python