当前位置:网站首页>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
边栏推荐
- Solution to the problem of automatic login in Yanshan University Campus Network
- Arduino gets the length of the array
- [offer9]用两个栈实现队列
- Esp8266 uses Arduino to connect Alibaba cloud Internet of things
- Database course design: college educational administration management system (including code)
- Amba, ahb, APB, Axi Understanding
- Minio file download problem - inputstream:closed
- [899] ordered queue
- 记一次云服务器被密码爆破的经历——关小黑屋、改密码、改端口
- Symbolic representation of functions in deep learning papers
猜你喜欢
Feature of sklearn_ extraction. text. CountVectorizer / TfidVectorizer
Navigator object (determine browser type)
ESP8266连接onenet(旧版MQTT方式)
Esp8266 uses Arduino to connect Alibaba cloud Internet of things
open-mmlab labelImg mmdetection
Types de variables JS et transformations de type communes
Classification, understanding and application of common methods of JS array
Intermediate use tutorial of postman [environment variables, test scripts, assertions, interface documents, etc.]
(1) Introduction Guide to R language - the first step of data analysis
Amba, ahb, APB, Axi Understanding
随机推荐
Solution to the problem of automatic login in Yanshan University Campus Network
Arduino JSON data information parsing
Easy to use shortcut keys in idea
JS function promotion and declaration promotion of VaR variable
Stm32f1+bc20+mqtt+freertos system is connected to Alibaba cloud to transmit temperature and humidity and control LED lights
Minio file download problem - inputstream:closed
Postman 中级使用教程【环境变量、测试脚本、断言、接口文档等】
燕山大学校园网自动登录问题解决方案
Single chip Bluetooth wireless burning
Knowledge summary of request
ES6 grammar summary -- Part 2 (advanced part es6~es11)
idea问题记录
Arduino gets the length of the array
Redis 缓存更新策略,缓存穿透、雪崩、击穿问题
Fashion Gen: the general fashion dataset and challenge paper interpretation & dataset introduction
Gateway fails to route according to the service name, and reports an error service unavailable, status=503
[offer29] sorted circular linked list
2021.11.10汇编考试
Common DOS commands
[leetcode19]删除链表中倒数第n个结点