原题:

You are given an integer array sorted in ascending order (may contain duplicates), you need to split them into several subsequences, where each subsequences consist of at least 3 consecutive integers. Return whether you can make such a split.

Example 1:

Input: [1,2,3,3,4,5]
Output: True
Explanation:
You can split them into two consecutive subsequences :
1, 2, 3
3, 4, 5

Example 2:

Input: [1,2,3,3,4,4,5,5]
Output: True
Explanation:
You can split them into two consecutive subsequences :
1, 2, 3, 4, 5
3, 4, 5

Example 3:

Input: [1,2,3,4,4,5]
Output: False

Note:

  1. The length of the input is in range of [1, 10000]

写个这个玩意还真是费尽。。。

代码如下:

bool isPossible(int* nums, int numsSize) {if(numsSize<3)return false;struct listnode{int lastnum;int count;};struct listnode* test;test=(struct listnode*)malloc(sizeof(struct listnode)*20000);int amount=0;for(int n=0;n<numsSize;n++){int flag=1;for(int m=amount-1;m>=0;m--){if((test+m)->lastnum==(*(nums+n)-1)){flag=0;(test+m)->lastnum+=1;(test+m)->count+=1;break;}}if(flag==1){(test+amount)->lastnum=*(nums+n);(test+amount)->count=1;amount++;}}for(int n=0;n<amount;n++){//printf("F%d",(test+n)->count);if((test+n)->count<3)return false;}return true;
}

就是构建几个桶一样,往里面扔数字,规则就是从后往前(时间顺序)。

最后检索有没有桶不够三个。

得出结论。

leetcode 659. Split Array into Consecutive Subsequences相关推荐

  1. LeetCode 659 Split Array into Consecutive Subsequences

    LeetCode Brute Force的方法就是把维护这些字串,每次来新的就加入到符合条件的但是最短的字串中去. 因为不需要求这些字串,可以做一些优化,用字串最后一位数作为key,把长度存入一个di ...

  2. LeetCode 410. Split Array Largest Sum

    方法一:DFS+Memoization 某种程度来说本题和 Word Break 很像.直接dfs暴力做肯定会超时,加上memoization即可. dfs(start, m, ...) 表示从ind ...

  3. leetcode 330. Patching Array | 1798. Maximum Number of Consecutive Values You Can Make

    1798. Maximum Number of Consecutive Values You Can Make | 1798. 你能构造出连续值的最大数目 https://leetcode.com/p ...

  4. LeetCode 905 Sort Array By Parity--Java stream,Python lambda表达式一行 解法

    题目地址:Sort Array By Parity - LeetCode Given an array A of non-negative integers, return an array cons ...

  5. LeetCode 659. 分割数组为连续子序列

    LeetCode 659. 分割数组为连续子序列 回顾 根据题意,每个元素只会涉及两种情况: 已经存在nums[i]-1结尾的序列,我们把nums[i]接到之前的某个序列后. 尝试以nums[i]为头 ...

  6. [勇者闯LeetCode] 189. Rotate Array

    [勇者闯LeetCode] 189. Rotate Array Description Rotate an array of n elements to the right by k steps. F ...

  7. leetcode 485,487,1004. Max Consecutive Ones I ,II, III(最大连续1的个数问题合集)

    485. Max Consecutive Ones https://leetcode.com/problems/max-consecutive-ones/ easy 题,思路不说了,直接上代码. cl ...

  8. 【LeetCode】954. Array of Doubled Pairs 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  9. [Leetcode] Merge Sorted Array 合并数组

    Merge Sorted Array 最新更新请见:https://yanjia.me/zh/2019/02/... Given two sorted integer arrays nums1 and ...

最新文章

  1. SVN 报错“Previous operation has not finished; run ‘cleanup‘ if it was interrupted”
  2. POJ1038 Bugs Integrated, Inc.
  3. 配置切入点表达式|| 前置通知、后置通知、异常通知、最终通知、环绕通知
  4. Java多线程(四):使用Executors创建线程池及其注意事项
  5. Vue + ESLint——编译错误[‘xxx‘ is defined but never used]解决方案
  6. 没有 root 权限如何使用 pip?How to install python modules without root access?
  7. Docker运行GUI软件的方法
  8. Magento 模块详解
  9. Windows 2008 R2阿里云安全基线检查
  10. JAVA爬虫实践(实践二:博客园)
  11. 让Mootools的语法结构像Jquery那样
  12. 263. Ugly Number
  13. 德赛西威领投智驾科技B轮3亿元,加速智能驾驶人人可享
  14. 渗透测试web安全 - webshell 免杀 绕过waf总结
  15. 【T+】win10/win11系统安装畅捷通T+Cloud专属云18.0
  16. 大二 数据结构 期末复习题(仅供参考)
  17. 电脑网页截长屏最简单的方法
  18. 办公自动化和计算机应用哪个好,高级办公自动化和计算机二级VF哪个更好?两个都考有必要吗?...
  19. OpenCV50:使用SVM完成OCR手写体识别
  20. f检验matlab计算,方差分析F检验的步骤和判定

热门文章

  1. 立体匹配的研究背景以及意义
  2. 台式计算机必备硬件,DIY台式电脑主机六大硬件
  3. ElasticSearch入门1
  4. 机械动作时序图怎么画_时序图怎么画步骤教程_时序图用什么工具画_时序图的作用是什么...
  5. MAMP安装pcntl扩展(其他扩展同理)
  6. 电脑密码忘记了怎么处理(针对按F8没反应的处理)
  7. 【四圣龙神录的编程教室】第21章、给自机加上碰撞检测和无敌效果吧
  8. linux指令which和whereis的区别
  9. lua服务执行过程中协程的挂起和重新唤醒
  10. mysql 规则引擎_Drools规则引擎详解-常用的drl实例