当前位置:网站首页>Game 280 weekly
Game 280 weekly
2022-07-06 12:34:00 【Yake1965】
The first 280 Weekly match
- [*6004. obtain 0 The number of operations ](https://leetcode-cn.com/problems/count-operations-to-obtain-zero/)
- [6005. The minimum number of operands to make an array an alternating array ](https://leetcode-cn.com/problems/minimum-operations-to-make-the-array-alternating/)
- 6006. Take out the smallest number of magic beans
- 6007. The maximum sum of the array
*6004. obtain 0 The number of operations
class Solution:
def countOperations(self, num1: int, num2: int) -> int:
res = 0
# Ordinary people solve
# while num1 and num2:
# res += 1
# if num1 > num2: num1 -= num2
# else: num2 -= num1
# * Bull man solution : division Lingcha mountain AI house
while num1 > 0:
res += num2 // num1
num1, num2 = num2 % num1, num1
return res
class Solution {
public int countOperations(int num1, int num2) {
int res = 0;
while (num1 > 0){
res += num2 / num1;
int tmp = num1;
num1 = num2 % num1;
num2 = tmp;
}
return res;
}
}
6005. The minimum number of operands to make an array an alternating array
class Solution:
def minimumOperations(self, nums: List[int]) -> int:
n = len(nums)
if n == 1: return 0
a, b = Counter(nums[::2]), Counter(nums[1::2])
a = sorted(a.items(), key = lambda x: -x[1])
b = sorted(b.items(), key = lambda x: -x[1])
if a[0][0] != b[0][0]: # In two arrays , The elements that appear most often are different
return n - a[0][1] - b[0][1]
else:
cost0 = n - a[0][1] - (0 if len(b) == 1 else b[1][1])
cost1 = n - b[0][1] - (0 if len(a) == 1 else a[1][1])
return min(cost0, cost1)
6006. Take out the smallest number of magic beans
6007. The maximum sum of the array
边栏推荐
- Intermediate use tutorial of postman [environment variables, test scripts, assertions, interface documents, etc.]
- How to add music playback function to Arduino project
- [leetcode622]设计循环队列
- Gateway 根据服务名路由失败,报错 Service Unavailable, status=503
- Esp8266 connects to bafayun (TCP maker cloud) through Arduino IED
- Minio file download problem - inputstream:closed
- [esp32 learning-1] construction of Arduino esp32 development environment
- Gateway fails to route according to the service name, and reports an error service unavailable, status=503
- Knowledge summary of request
- Database course design: college educational administration management system (including code)
猜你喜欢
随机推荐
ES6语法总结--下篇(进阶篇 ES6~ES11)
JS变量类型以及常用类型转换
ES6 grammar summary -- Part 2 (advanced part es6~es11)
MySQL時間、時區、自動填充0的問題
[golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree
Stm32f1+bc20+mqtt+freertos system is connected to Alibaba cloud to transmit temperature and humidity and control LED lights
dosbox第一次使用
Compilation principle: preprocessing of source program and design and implementation of lexical analysis program (including code)
[leetcode15] sum of three numbers
2021.11.10 compilation examination
Feature of sklearn_ extraction. text. CountVectorizer / TfidVectorizer
Gateway fails to route according to the service name, and reports an error service unavailable, status=503
Force buckle 1189 Maximum number of "balloons"
[899]有序队列
Easy to use shortcut keys in idea
Redis based distributed ID generator
SSD technical features
Pat 1097 duplication on a linked list (25 points)
Rough analysis of map file
单片机蓝牙无线烧录









