leetcode
文章平均质量分 53
maryhaocool2023
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
C/C++ INT_MAN与INT_MIN
INT_MAX = 2147483647, 二进制为01111111111111111111111111111111 =0x7fffffff = 2^31-1;INT_MIN = -2147483648, 为2147483648的相反数,= -2^31 ;实际上已经溢出了;-2147483648只是一个表达式。在计算机中补码:10000000000000000000000000000000...原创 2019-08-05 10:04:27 · 527 阅读 · 0 评论 -
100-200 Leetcode 题目总结(下)
8.Breadth - first depth50)第一百九十九题 Binary Tree Side View类似层序遍历一百零二题,返回最右边的值52)第一百零二题 Binary Tree Level Order Traversallevel 表示层数53)第一百零三题 Binary Tree Zigzag Level Order Traversal不能left righ...原创 2020-03-30 21:13:34 · 261 阅读 · 0 评论 -
200-300 leetcode (下)
1. Array 228,229,238,243,245,277,289,2.String214,227,271,293,3.Math223,233,247,248,258,263,273,4.Design 208,251,281,284,5.Heap215,218,239,253,295,6.Backtracking211,212,216,25...原创 2020-03-03 02:59:10 · 215 阅读 · 0 评论 -
200-300 leetcode (上)
1hash202,217,219,242,244,246,266204:找质数?205:两者必须一一对应,例子"ab" "aa",map 两次,清空一次249:把string都map到一类值,比如以a开头的string,或者数值字符串“123” (c+26-a[0])%26for(auto it = m.begin();it!=m.end();it++) res.push_b...原创 2020-02-25 21:22:41 · 186 阅读 · 0 评论 -
100-200 Leetcode 题目总结(上)
一.Array1).第一百一十八题Pascal's Trianglevector.assign(n,vector<int>(1)) ; 每个放入一个0;vector.assign(n,vector<int>(1,1)) ; 每个放入一个1;2).第一百一十九题 Pascal's Triangle II1.res.assign(n+1,1);2.fo...原创 2020-01-04 06:50:36 · 630 阅读 · 0 评论 -
51-100 Leetcode 题目总结
1 Array第五十四题: Spiral Matrix本题可以设置一个top,bottom,left,right 等通过++,--来改变边界。注意:1 if(matrix.size()==0) return res; 2if(top>bottom) break;if(left>right) break; 3 定义:vec...原创 2019-08-21 09:25:15 · 272 阅读 · 0 评论 -
Leetcode 五十四题 Spiral Matrix
第五十四题: Spiral Matrix本题可以设置一个top,bottom,left,right 等通过++,--来改变边界。注意:1 if(matrix.size()==0) return res; 2if(top>bottom) break;if(left>right) break; 3 定义:vector<ve...原创 2019-09-20 04:14:58 · 111 阅读 · 0 评论 -
leetcode 七十三题: Set Matrix Zeros
七十三题: Set Matrix Zeros本题要求in_place,遍历四次,第一次用vector存为0的i,第二次用vector存为0的j,第三次把i置为0,第四次把j置为0. class Solution {public: vector<string> fullJustify(vector<string>& words, int maxWid...原创 2019-09-20 04:16:14 · 177 阅读 · 0 评论 -
前50道Leetcode总结
Leetcode总结1.Two Pointers SUMS 类型: 第十五题:3SUMS: 1.三层重复值跳过,i+left+right;2.排序后当前值大于目标值提前退出 注:也可以用Hash,但是复杂度不会有变化 N^2,还有一个小弊端就是第一层重复值不能跳过 第十六...原创 2019-02-14 16:41:37 · 521 阅读 · 1 评论 -
Copy List with Random Pointer
/*** Definition for singly-linked list with a random pointer.* struct RandomListNode {* int label;* RandomListNode *next, *random;* RandomListNode(int x) : label(x), next(NU原创 2017-06-04 16:20:14 · 173 阅读 · 0 评论 -
Maximal Square
本题有传承的思想,因此要用到动态规划。如下图所示,右下角的result应该是所在正方形中最小的2加1代码如下:class Solution {public: int maximalSquare(vector>& matrix) { int m=matrix.size(),n,res=0; if(m) {原创 2017-04-06 18:56:03 · 183 阅读 · 0 评论 -
Interleaving String leetcode
AC代码:class Solution {public: bool isInterleave(string s1, string s2, string s3) { int i=0,m=s1.size(),n=s2.size();bool matrix[m+1][n+1]; if((s1==""&&s2==s3)||(s2==""&&s1==s3))原创 2016-07-27 11:04:17 · 214 阅读 · 0 评论 -
Best Time to Buy and Sell Stock II
本题属于动态dp,buy表示到目前i为止最后一个状态是买(有可能之前买的最近一直没卖,有可能是刚买的)sell表示到目前i为止最后一个状态是卖(有可能之前卖了最近一直没买,有可能刚卖的)注意一下两个递推公式: buy=max(buy,sell-prices[i]);sell=max(sell,buy+prices[i原创 2016-07-19 10:55:22 · 206 阅读 · 0 评论 -
H-Index leetcode
本题目最重要的是要读懂题意超过h的个数为h,超过h+1的个数小于h+1都为h比如citations = [3, 0, 6, 1, 5]不小于3的有3个,h=3;比如citations = [1,1] 不小于1的有2个,但是不小于2的有0个,h=1;AC代码:class Solution {public: int hIndex(vector& citations)原创 2016-07-19 18:21:39 · 289 阅读 · 0 评论 -
Reverse Bits leetcode
本题可以运用普通数字转二进制解决AC代码:class Solution {public: uint32_t reverseBits(uint32_t n) { int array[32];int res=0; for(int i=0;i<32;i++){ array[i]=n&1; n=n原创 2016-07-19 20:31:35 · 235 阅读 · 0 评论 -
Number of Digit One leetcode
Number of Digit One本题思路为分有几个1的情况讨论,即有1个1时,有2个1时......AC代码:class Solution {public: int plzh(int m){ int res=1; for(int i=2;i<=m;i++) res*=i; return res; } in原创 2016-08-01 10:15:47 · 214 阅读 · 0 评论 -
Valid Palindrome leetcode
Valid Palindrome本题比较简单,用两个指针从两头开始遍历即可AC代码:class Solution {public: bool isletter(char n){ if((n>='a'&&n='A'&&n<='Z')) return true; return false; }原创 2016-07-22 09:35:45 · 206 阅读 · 0 评论 -
Valid Number leetcode
本题需要注意的是边界条件设置过多,因此通过率不高。"0"=>true" 0.1 "=>true"abc"=>false"1 a"=>false"2e10"=>true除了上述题目给出的边界条件以外,还有下述需要注意的例子:" 005047e+6"=>true"32.e-80123"=>true"46.e3"=>true原创 2016-07-21 14:43:23 · 272 阅读 · 0 评论 -
Spiral Matrix leetcode
[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]本题要求用You should return[1,2,3,6,9,8,7,4,5].public:vector spiralOrder(vector>& matrix) {vector res;if(!matrix.empty()){int m=matrix.siz原创 2016-07-16 20:08:47 · 243 阅读 · 0 评论 -
Multiply Strings leetcode
Multiply Strings本题需要注意char型超过10的时候不为10,因此可以先转化为int型运算,运算原理同乘法相同AC代码:class Solution {public: string reverse(string s){ for(int i=0;i<s.size()/2;i++){ int temp=s[i];原创 2016-07-24 15:32:28 · 212 阅读 · 0 评论
分享