leetcode再次总结
注释 testcases
(1)简单一想O(n)算法,有可能通过二分查找变形优化成log(n)
(2)双指针:一快一慢 一静一动(数组中最小的长度满足条件,常常用于,确定了一个范围,然后一个指针静止,一个指针收缩) 一前一后
(3)二分查找可以一次性做完,也可以分两次来做,一次用于二分查找左边确定左边界,一次用于二分查找确定右边界。
(4)数字理解成二进制的方法,就是通过一个bitvector,简而言之一个32位的数组,循环每一位进行处理。
(5)Maximum Subarray 问题,用localMax 记录每一次局部最大值,全局的最大值是局部最大值的最大值。
(6)找一个数字[1,n]中满足某个条件的数字,也可以把数字看成一个数组,通过采用二分查找的方式解决。
(7)一个hashmap 不够就用两个,一个用于记录原始的key,value值,一个用于扫描式和原始的hashmap进行比对。
(8)对于数学规律题,一定要多写几个case观察规律,尤其是数组中的规律问题。
(9)在代码写完之时,一定一定一定不能急,要写好test case
(10)多用hashset hashmap 利用空间复杂度先解决问题为上策
(11)一旦涉及到两个数的关系( ret = (((dividend ^ divisor) >> 31) & 1) == 1 ? -ret: ret;),就要考虑到两个数是正负号问题,是否会溢出问题。
(12)stack的应用不一定要存value 也可以存index,存index的好处是 一方面可以通过index获取到value 另外一方面可以通过Index解决 最长 最短问题。
leetcode再次总结的更多相关文章
- [LeetCode] Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串
Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...
- Leetcode 笔记 98 - Validate Binary Search Tree
题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...
- Leetcode 笔记 36 - Sudoku Solver
题目链接:Sudoku Solver | LeetCode OJ Write a program to solve a Sudoku puzzle by filling the empty cells ...
- [LeetCode] Matchsticks to Square 火柴棍组成正方形
Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...
- [LeetCode] Split Array Largest Sum 分割数组的最大值
Given an array which consists of non-negative integers and an integer m, you can split the array int ...
- [LeetCode] Coin Change 硬币找零
You are given coins of different denominations and a total amount of money amount. Write a function ...
- [LeetCode] Additive Number 加法数
Additive number is a positive integer whose digits can form additive sequence. A valid additive sequ ...
- [LeetCode] Word Pattern II 词语模式之二
Given a pattern and a string str, find if str follows the same pattern. Here follow means a full mat ...
- [LeetCode] Single Number III 单独的数字之三
Given an array of numbers nums, in which exactly two elements appear only once and all the other ele ...
随机推荐
- FFmpeg被声明为已否决的解决方案
参考雷神的最简单的打印Hello World的程序: #include <stdio.h> #include <string.h> extern "C" { ...
- Windows 7中的“帮助和支持”无法打开怎么办?
win7 X64 将下面的代码导入注册表 Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\.xml] @="xmlfile&q ...
- Codeforces Gym101234G Dreamoon and NightMarket(优先队列,子集和第k大)
题意: 求子集和第k大,n,k<=1e6 思路: 优先队列经典题目,注意优先队列是默认按从大到小排的 代码: #include<iostream> #include<cstdi ...
- DOCKER 学习笔记9 Kubernetes (K8s) 生产级容器编排 上
前言 在上一节的学习中.我们已经可以通过最基本的 Docker Swarm 创建集群,然后在集群里面加入我们需要运行的任务 以及任务的数量 这样我们就创建了一个服务. 当然,这样的方式在我们本地虚拟机 ...
- learn about sqlserver partitition and partition table 1
Dear all, Let get into business, the partitions on sql server is very different with that on oracle. ...
- Keepalived & LVS: 实现web的负载均衡和高可用
目录 1. 环境介绍2. LVS DR模型中Realserver上的准备3. ha上的准备4. 配置keepalived5. 测试Realserver的切换6. failback页面测试7. keep ...
- Coroutine 预激装饰器
预激装饰器 讨论如何终止协程之前,我们要先谈谈如何启动协程.使用协程之前必须预激,可是这一 步容易忘记.为了避免忘记,可以在协程上使用一个特殊的装饰器.接下来介绍这样一个 装饰器. 预激协程的装饰器, ...
- javascript检测客户端环境是否是pc端
//isPC(): 检测客户端环境是否是pc端 function isPC(){ let userAgent = navigator.userAgent; let agents = ["An ...
- 大文件切割(split)
split提供两种方式对文件进行切割: 根据行数切割,通过-l参数指定需要切割的行数 根据大小切割,通过-b参数指定需要切割的大小 1.1 根据行数切割 如下以一个3.4G大小的日志文件做切割演示,每 ...
- WebSocket协议分析
WebSocket协议分析 1.什么是WebSocket协议 WebScoket协议是基于TCP协议建立的全双工通信,所谓的全双工通信就是双向同时通信. 2.WebSocket协议优点 WebSock ...