当前位置:网站首页>Simulation volume leetcode [general] 1296 Divide an array into a set of consecutive numbers
Simulation volume leetcode [general] 1296 Divide an array into a set of consecutive numbers
2022-07-06 06:18:00 【Encounter simulation volume】
1296. Divide an array into a set of consecutive numbers
Give you an array of integers nums And a positive integer k, Please judge whether this array can be divided into some by k A set of consecutive numbers .
If possible , Please return true; otherwise , return false.
Example 1:
Input :nums = [1,2,3,3,4,4,5,6], k = 4
Output :true
explain : The array can be divided into [1,2,3,4] and [3,4,5,6].
Example 2:
Input :nums = [3,2,1,2,3,4,3,4,5,9,10,11], k = 3
Output :true
explain : The array can be divided into [1,2,3] , [2,3,4] , [3,4,5] and [9,10,11].
Example 3:
Input :nums = [3,3,2,2,1,1], k = 3
Output :true
Example 4:
Input :nums = [1,2,3,4], k = 3
Output :false
explain : The array cannot be divided into several sizes 3 Subarray .
Tips :
1 <= k <= nums.length <= 105
1 <= nums[i] <= 109
Be careful : This topic is related to 846 repeat :https://leetcode-cn.com/problems/hand-of-straights/
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/divide-array-in-sets-of-k-consecutive-numbers
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Code :
from leetcode_python.utils import *
class Solution:
def __init__(self):
pass
def isPossibleDivide(self, nums: List[int], k: int) -> bool:
if len(nums)%k>0:return False
cnt = Counter(nums)
while cnt:
x = min(cnt)
for n in range(x,x+k):
if cnt[n]==1:cnt.pop(n)
elif cnt[n]>1:cnt[n]-=1
else:return False
return True
def test(data_test):
s = Solution()
data = data_test # normal
# data = [list2node(data_test[0])] # list turn node
return s.getResult(*data)
def test_obj(data_test):
result = [None]
obj = Solution(*data_test[1][0])
for fun, data in zip(data_test[0][1::], data_test[1][1::]):
if data:
res = obj.__getattribute__(fun)(*data)
else:
res = obj.__getattribute__(fun)()
result.append(res)
return result
if __name__ == '__main__':
datas = [
[],
]
for data_test in datas:
t0 = time.time()
print('-' * 50)
print('input:', data_test)
print('output:', test(data_test))
print(f'use time:{
time.time() - t0}s')
remarks :
GitHub:https://github.com/monijuan/leetcode_python
CSDN Summary : Simulation volume Leetcode Summary of questions _ Paper blog -CSDN Blog
You can add QQ Group communication :1092754609
leetcode_python.utils See the description on the summary page for details
First brush questions , Then generated by script blog, If there is any mistake, please leave a message , I see it will be revised ! thank you !
边栏推荐
- 单元测试的意义
- Detailed explanation of P problem, NP problem, NPC problem and NP hard problem
- Eigen sparse matrix operation
- Manhattan distance sum - print diamond
- [postman] the monitors monitoring API can run periodically
- MySQL之基础知识
- F - True Liars (种类并查集+DP)
- 「 WEB测试工程师 」岗位一面总结
- Summary of anomaly detection methods
- 模拟卷Leetcode【普通】1062. 最长重复子串
猜你喜欢
【API接口工具】postman-界面使用介绍
PAT(乙级)2022年夏季考试
数字三角形模型 AcWing 1015. 摘花生
【Tera Term】黑猫带你学TTL脚本——嵌入式开发中串口自动化神技能
Win10 cannot operate (delete, cut) files
Full link voltage measurement: building three models
黑猫带你学UFS协议第4篇:UFS协议栈详解
Construction and integration of Zipkin and sleuth for call chain monitoring
keil MDK中删除添加到watch1中的变量
Selenium source code read through · 9 | desiredcapabilities class analysis
随机推荐
调用链监控Zipkin、sleuth搭建与整合
自定义指定路由上的Gateway过滤器工厂
JWT-JSON WEB TOKEN
Manhattan distance and Manhattan rectangle - print back font matrix
Digital triangle model acwing 1015 Picking flowers
数据库隔离级别
Testing and debugging of multithreaded applications
这些年用Keil遇到的坑
GTSAM中李群的運用
MySQL之数据类型
把el-tree选中的数组转换为数组对象
Manage configuration using Nacos
VINS-Mono: A Robust and Versatile Monocular Visual-Inertial State Estimator
Cannot create PoolableConnectionFactory (Could not create connection to database server. 错误
全程实现单点登录功能和请求被取消报错“cancelToken“ of undefined的解决方法
Buuctf-[[gwctf 2019] I have a database (xiaoyute detailed explanation)
GTSAM中李群的运用
「 WEB测试工程师 」岗位一面总结
MFC 动态创建的对话框及改变控件的大小和位置
Aike AI frontier promotion (2.13)