[leetcode整理]
=======简单
leetcode164 Maximum Gap sort两次
=======有参考
330 Patching Array
98 Validate Binary Search Tree BFS
60 Subsets II [done]
435 non-overlapping
public int eraseOverlapIntervals(Interval[] intervals) {
if (intervals == null || intervals.length == 0){
return 0;
}
Arrays.sort(intervals, new IntervalCompare());
int end = intervals[0].end;
int prev = 0;
int count = 0;
for(int i = 1; i < intervals.length; i++){
if(intervals[prev].end > intervals[i].start){
if(intervals[prev].end > intervals[i].end){
prev = i;
}
count++;
}
else{
prev = i;
}
}
return count;
}
455. Assign Cookies
class Solution {
public int findContentChildren(int[] g, int[] s) {
if(g == null || g.length == 0)return 0;
if(s == null || s.length == 0)return 0;
Arrays.sort(g);
Arrays.sort(s);
int cnt=0;
int i=0;
for(int gg:g){
while(i<s.length && gg>s[i]) i++;
if(i==s.length) break;
cnt++;
i++;
}
return cnt;
}
}
[leetcode整理]的更多相关文章
- leetcode整理(一)
leetcode题目整理,基本上不是最优解 1. 回文数 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 ...
- leetcode 整理
1.Two Sum 构造Comparator,KSum 这一类的问题最基本的一题, 解法: 先sort,然后双指针,头尾各一个.进行加逼找值. 对于其余的KSum最终是降次到2次. 如3Sum固定一个 ...
- LeetCode 到底怎么刷?GitHub 上多位大厂程序员亲测的高效刷题方式
作者:HelloGitHub-小鱼干 在众多的诸如阿里.腾讯等大厂之中,最看中面试者刷题技能的大概要数有"链表厂"之称的字节跳动了.作为一个新晋大厂,字节跳动以高薪.技术大佬云集吸 ...
- Leetcode——回溯法常考算法整理
Leetcode--回溯法常考算法整理 Preface Leetcode--回溯法常考算法整理 Definition Why & When to Use Backtrakcing How to ...
- Leetcode——二叉树常考算法整理
二叉树常考算法整理 希望通过写下来自己学习历程的方式帮助自己加深对知识的理解,也帮助其他人更好地学习,少走弯路.也欢迎大家来给我的Github的Leetcode算法项目点star呀~~ 二叉树常考算法 ...
- ACM金牌选手整理的【LeetCode刷题顺序】
算法和数据结构知识点图 首先,了解算法和数据结构有哪些知识点,在后面的学习中有 大局观,对学习和刷题十分有帮助. 下面是我花了一天时间花的算法和数据结构的知识结构,大家可以看看. 后面是为大家 精心挑 ...
- [leetcode] 提醒整理之进制
12. Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be with ...
- [leetcode] 题型整理之二叉树
94. Binary Tree Inorder Traversal Given a binary tree, return the inorder traversal of its nodes' va ...
- [leetcode] 题型整理之动态规划
动态规划属于技巧性比较强的题目,如果看到过原题的话,对解题很有帮助 55. Jump Game Given an array of non-negative integers, you are ini ...
随机推荐
- Skip level 1 on 1
2019-01-08 16:43:29 Skip level 1:1 什么是 Skip level 1 on 1 :你和你老板的老板(的老板) 1:1 如果你的老板是first line manag ...
- 提取出一个组装基因组的gap(N)和重复序列区域,保存为bed格式
参见: Question: How to extract allnon-seqencedpositions from a genome (Fasta file)? test.fa >chr1 N ...
- xml ----> 几个常用dtd头文件模板
环境: idea ce 2018.1 "File --> settings... --> Editor --> file and code templates" ...
- 『MXNet』第九弹_分类器以及迁移学习DEMO
解压文件命令: with zipfile.ZipFile('../data/kaggle_cifar10/' + fin, 'r') as zin: zin.extractall('../data/k ...
- 『MXNet』第六弹_Gluon性能提升
一.符号式编程 1.命令式编程和符号式编程 命令式: def add(a, b): return a + b def fancy_func(a, b, c, d): e = add(a, b) f = ...
- 4月12 php练习
php中输出 <?php echo'hello'; php中打印多个div <?php for($i=1;$i<=100;$i++) { ?> <div style=&q ...
- WEB环境相关技术、配置
一.简介(基本概念) web开发中基本概念和用到的技术: A — AJAX AJAX 全称为“ Asynchronous JavaScript and XML ”(异步 JavaScript 和 XM ...
- json加密
有的时候我们为了传参数的URL比较安全,我们一般会用json加密的方法来使自己的URL安全. $a['order_sn'] = $orderNo;$data = json_encode( $a);$d ...
- QQ企业邮箱接口
我推荐的这篇文章很好:http://wenku.baidu.com/link?url=KQIMyrECGb8GS_0fag4PRG64M8Z7wOLbsU1f3BhydXAyYJDC2JMHEuVcy ...
- Lucene.Net 学习(搜索部分)(低要求,写给自己看)
1. 搜索 排序:lucene 提供了Sort类对结果进行排序 提供了Filter类对查询条件进行限制 你或许会不自觉地拿它跟SQL语句进行比较:“lucene能执行and.or.order by.w ...