当前位置:网站首页>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
边栏推荐
- Gateway fails to route according to the service name, and reports an error service unavailable, status=503
- Common properties of location
- Single chip Bluetooth wireless burning
- Walk into WPF's drawing Bing Dwen Dwen
- Important methods of array and string
- Problèmes avec MySQL time, fuseau horaire, remplissage automatique 0
- (三)R语言的生物信息学入门——Function, data.frame, 简单DNA读取与分析
- Imgcat usage experience
- History object
- 基于Redis的分布式锁 以及 超详细的改进思路
猜你喜欢
Programmers can make mistakes. Basic pointers and arrays of C language
Stm32f1+bc20+mqtt+freertos system is connected to Alibaba cloud to transmit temperature and humidity and control LED lights
Redis based distributed locks and ultra detailed improvement ideas
JS正则表达式基础知识学习
Classification, understanding and application of common methods of JS array
First use of dosbox
(4) Data visualization of R language -- matrix chart, histogram, pie chart, scatter chart, linear regression and strip chart
Basic operations of databases and tables ----- modifying data tables
Arduino JSON data information parsing
Arduino uno R3 register writing method (1) -- pin level state change
随机推荐
js 变量作用域和函数的学习笔记
Arduino gets the length of the array
Design and implementation of general interface open platform - (39) simple and crude implementation of API services
MySQL replacement field part content
Feature of sklearn_ extraction. text. CountVectorizer / TfidVectorizer
Imgcat usage experience
Kconfig Kbuild
Knowledge summary of request
Solution to the problem of automatic login in Yanshan University Campus Network
[Offer29] 排序的循环链表
Whistle+switchyomega configure web proxy
Gateway 根据服务名路由失败,报错 Service Unavailable, status=503
如何给Arduino项目添加音乐播放功能
(3) Introduction to bioinformatics of R language - function, data Frame, simple DNA reading and analysis
Minio file download problem - inputstream:closed
Latex learning
HCIP Day 12
Unity3D制作注册登录界面,并实现场景跳转
编译原理:源程序的预处理及词法分析程序的设计与实现(含代码)
[leetcode19] delete the penultimate node in the linked list