当前位置:网站首页>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
边栏推荐
- Redis 缓存更新策略,缓存穿透、雪崩、击穿问题
- Esp8266 connects to onenet cloud platform (mqtt) through Arduino IDE
- Kaggle competition two Sigma connect: rental listing inquiries (xgboost)
- [899] ordered queue
- JS variable types and common type conversions
- 2022.2.12 resumption
- 数据库课程设计:高校教务管理系统(含代码)
- VSCode基础配置
- Basic operations of databases and tables ----- view data tables
- MySQL replacement field part content
猜你喜欢
ESP8266连接onenet(旧版MQTT方式)
JS變量類型以及常用類型轉換
ESP learning problem record
Programming homework: educational administration management system (C language)
(5) Introduction to R language bioinformatics -- ORF and sequence analysis
NRF24L01故障排查
Basic operations of databases and tables ----- classification of data
E-commerce data analysis -- salary prediction (linear regression)
JS正则表达式基础知识学习
Fashion Gen: the general fashion dataset and challenge paper interpretation & dataset introduction
随机推荐
[leetcode19]删除链表中倒数第n个结点
Unity3D,阿里云服务器,平台配置
(一)R语言入门指南——数据分析的第一步
ES6 grammar summary -- Part 2 (advanced part es6~es11)
Mp3mini playback module Arduino < dfrobotdfplayermini H> function explanation
Whistle+switchyomega configure web proxy
2022.2.12 resumption
Amba, ahb, APB, Axi Understanding
[offer78]合并多个有序链表
[offer29] sorted circular linked list
@The difference between Autowired and @resource
[Offer18]删除链表的节点
idea中导包方法
Basic operations of databases and tables ----- classification of data
idea中好用的快捷键
[leetcode15] sum of three numbers
Walk into WPF's drawing Bing Dwen Dwen
open-mmlab labelImg mmdetection
[leetcode622]设计循环队列
Office提示您的许可证不是正版弹框解决