top错误
来源:互联网 发布:淘宝代销分账要钱吗 编辑:程序博客网 时间:2024/06/07 01:08
3. Longest Substring Without Repeating Characters
长度计算错误,无ac
4. Median of Two Sorted Arrays
两个有序数组的中位数,按照位置进行切分,分别对位置的左右两边进行切分,切分成功后,mid1 + mid2 = m + n , 分别求出切分点两端的点。
14. Longest Common Prefix
错误:返回时出现问题,如果出现break,立刻返回
15. 3Sum
错误,未考虑重复元素
19. Remove Nth Node From End of List
错误:原来的快行指针挺好,也能考虑到长度的问题,也能考虑到删除头的问题
22. Generate Parentheses
错误:忽略了条件, 当填充右括号的时候,那必须左括号用的多!
26. Remove Duplicates from Sorted Array
很巧妙的写法:
for(int n : nums) if (n > nums[i - 1]) nums[i ++] = n;
28. Implement strStr()
注意:next[j - 1]
29. Divide Two Integers
要求:位操作实现除法
错误:在实现abs的时候,没有把integer转化为long,导致负数错误
旋转数组3查找
33. Search in Rotated Sorted Array
思路:判断lo到mid是否是上升的
然后在处理,适用于没有重复元素的情况
81. Search in Rotated Sorted Array II
数组中存在重复元素如何处理
思路:通过判断mid 和hi位置的元素的大小,进行二分查找, 如果mid和hi的相等,那么hi–
while(lo < hi){ mid=(lo+hi) / 2; if(A[mid]==target) return true; if(A[mid] > A[hi]){ if(A[mid] > target && A[lo] <= target) hi = mid - 1; else lo = mid + 1; }else if(A[mid] < A[hi]){ if(A[mid] < target && A[hi] >= target) lo = mid + 1; else hi = mid - 1; }else{ hi--; } }
153. Find Minimum in Rotated Sorted Array
取数组的最后一个作为tar,然后查找第一个小于tar的值,不涉及到最后一次出现的情况,不用start+1 < end
注意每次对比的是target的值,
34. Search for a Range
要求:找一个数的左右两边的边界点,
思路:先二分找左边界,注意 if (mid <= 0 || nums[mid - 1] < target) 再二分找右边界
if (left2 == -1) left2 = mid;
if (right2 == -2) right2 = right;
优美的代码:
if (A.length <= 0) { return new int[]{-1, -1}; } int i = 0, j = A.length - 1; int[] resu = new int[2]; // Search for the left one while (i < j) { **int mid = (i + j) /2;** if (A[mid] < target) i = mid + 1; else j = mid; } if (A[i]!=target) return resu; else resu[0] = i; // Search for the right one j = A.length - 1; // We don't have to set i to 0 the second time. while (i < j) { **int mid = (i + j) /2 + 1;** // Make mid biased to the right if (A[mid] > target) j = mid - 1; else i = mid; // So that this won't make the search range stuck. } resu[1] = j; return resu;
46. Permutations
要求:对于输出特定结果的,基本上使用backtracking
https://leetcode.com/problems/permutations/discuss/
48. Rotate Image
旋转图像,矩阵上面的知识,顺时针,行交换,对称
逆时针,列交换,对称
50. Pow(x, n)
代码没写出来
//优美的代码 public double pow(double x, int n) { if(n == 0) return 1; if(n<0){ n = -n; x = 1/x; } return (n%2 == 0) ? pow(x*x, n/2) : x*pow(x*x, n/2); }
54. Spiral Matrix
螺旋状访问矩阵
定义了四个变量,rowBeg,rowEnd,colBeg,colEnd,向左向上需要判定
69. Sqrt(x)
二分法写的不对
75. Sort Colors
0,1,2,为了避免交换到i位置的也是2,所以用while循环
76. Minimum Window Substring
这个地方给unique不一样,对总的map,先对每个char弄成0,然后对每一个t里面的char加一,最后对字符串里面出现的
错误:在count为0的时候,要进行while循环,
78. Subsets
错误:判断的时候少写了个等号,
backtrack的时候resu没有新建,导致加进去的全是空
88. Merge Sorted Array
合并两个有序数组到,第一个有序数组里面去
101. Symmetric Tree
检查一个树是不是镜像树,传入的是两个节点,left,right,dfs, 注意help函数,树的题目,递归是个大法宝,两个节点都要传送
105. Construct Binary Tree from Preorder and Inorder Traversal
要求: root.left = bulidHelp(pre, in, preroot + 1, left, index - 1);
root.right = bulidHelp(pre, in, preroot + index - left + 1, index + 1, right);
在传送根节点的时候
124. Binary Tree Maximum Path Sum
考虑每个节点的为最长路径的最高节点
return Math.max(left, right) + root.val;
347. Top K Frequent Elements
map,list,list
最大子矩阵问题
之前遇到数组最大连续子数组的和,后来考虑降维处理,也是采用相同的dp方法。
- top错误
- margin-top的错误用法
- top后台执行显示:top: failed tty get 错误
- top后台执行显示:top: failed tty get 错误
- 最常犯的 HTML 标识错误 Top 100
- 使用top和jstack查找线程错误
- top
- top
- Top
- Top
- top
- top
- top
- top
- top
- top
- top
- top
- 自定义字符串定长拷贝函数my_strncpy()
- 快速理解Java中的五种单例模式
- 信号量sem_wait()的使用
- FTP发布VS2015网站项目
- 【机器学习】Kernel Logestic Regression 和Kernel SVM
- top错误
- 常见C++面试题及基本知识点总结(一)
- 打铁还需自身硬
- POSIX下的信号量(生产者&消费者模型)
- Unity制作UI界面时,在Sprite和UITexture之间如何选择?
- Jenkins+ant_实现Jmeter脚本持续集成测试实例
- error: ‘qVariantValue’ was not declared in this scope
- 网口扫盲一:网卡初步认识
- Arduino与ESP8266进行串口通信