当前位置:网站首页>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
边栏推荐
- Types de variables JS et transformations de type communes
- Vscode basic configuration
- Database course design: college educational administration management system (including code)
- Solution to the problem of automatic login in Yanshan University Campus Network
- JS变量类型以及常用类型转换
- AMBA、AHB、APB、AXI的理解
- 2022.2.12 resumption
- Rough analysis of map file
- Compilation principle: preprocessing of source program and design and implementation of lexical analysis program (including code)
- Stm32f1+bc20+mqtt+freertos system is connected to Alibaba cloud to transmit temperature and humidity and control LED lights
猜你喜欢

js题目:输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。

JS variable types and common type conversions

SVN更新后不出现红色感叹号

單片機藍牙無線燒錄

Learning notes of JS variable scope and function

JS 函数提升和var变量的声明提升
![[Clickhouse kernel principle graphic explanation] about the collaborative work of partitioning, indexing, marking and compressed data](/img/28/221b0a51ef5f2e8ed5aeca2de8f463.jpg)
[Clickhouse kernel principle graphic explanation] about the collaborative work of partitioning, indexing, marking and compressed data

Pytorch: tensor operation (I) contiguous

记一次云服务器被密码爆破的经历——关小黑屋、改密码、改端口

Esp8266 uses Arduino to connect Alibaba cloud Internet of things
随机推荐
1041 Be Unique (20 point(s))(哈希:找第一个出现一次的数)
JS Title: input array, exchange the largest with the first element, exchange the smallest with the last element, and output array.
RuntimeError: cuDNN error: CUDNN_ STATUS_ NOT_ INITIALIZED
About using @controller in gateway
[offer78]合并多个有序链表
How to add music playback function to Arduino project
Navigator object (determine browser type)
MySQL時間、時區、自動填充0的問題
Unity3D制作注册登录界面,并实现场景跳转
[Red Treasure Book Notes simplified version] Chapter 12 BOM
@The difference between Autowired and @resource
Kaggle competition two Sigma connect: rental listing inquiries (xgboost)
[offer9] implement queues with two stacks
Basic operations of databases and tables ----- modifying data tables
[Offer29] 排序的循环链表
(5) Introduction to R language bioinformatics -- ORF and sequence analysis
Flink late data processing (3)
Gravure sans fil Bluetooth sur micro - ordinateur à puce unique
Force buckle 1189 Maximum number of "balloons"
Solution to the problem of automatic login in Yanshan University Campus Network