排序:
https://leetcode-cn.com/problems/shortest-unsorted-continuous-subarray/
二分查找
https://leetcode-cn.com/problems/binary-search/
【】二分搜索
https://leetcode-cn.com/problems/search-insert-position/
【】二分搜索+为-1时返回应插入的位置
二叉搜索树
https://leetcode-cn.com/problems/search-in-a-binary-search-tree/
https://leetcode-cn.com/problems/trim-a-binary-search-tree/
【】https://blog.csdn.net/hy971216/article/details/81570498
【】https://blog.csdn.net/LSGO_MYP/article/details/92796893
https://leetcode-cn.com/problems/range-sum-of-bst/
【】https://blog.csdn.net/qq_17550379/article/details/84034131
https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree/ 【】https://www.cnblogs.com/eilearn/p/9394672.html
https://leetcode-cn.com/problems/find-mode-in-binary-search-tree/
【】中序遍历后求众数
https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/
【】中序遍历 求相邻元素的差值
https://leetcode-cn.com/problems/minimum-distance-between-bst-nodes/
【】中序遍历
https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/
【】马老师
二叉树遍历
https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/
【】马老师
https://leetcode-cn.com/problems/maximum-subarray/solution/hua-jie-suan-fa-53-zui-da-zi-xu-he-by-guanpengchn/
class Solution {
public int maxSubArray(int[] nums) {
int ans = nums[0];
int sum = 0;
for(int num: nums) {
if(sum > 0) {
sum += num;
} else {
sum = num;
}
ans = Math.max(ans, sum);
}
return ans;
}
https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/
【】终止条件、返回值和递归过程:
当前节点root为空时,说明此处树的高度为0,0也是最小值
当前节点root的左子树和右子树都为空时,说明此处树的高度为1,1也是最小值
如果为其他情况,则说明当前节点有值,且需要分别计算其左右子树的最小深度,返回最小深度+1,+1表示当前节点存在有1个深度
图
https://leetcode-cn.com/problems/unique-paths-ii/
【】无障碍递归
public static int rec_uniquePaths(int m,int n) {
if(m == 1 && n == 1) return 1;
if(m == 1) return rec_uniquePaths(m, n - 1);
if(n == 1) return rec_uniquePaths(m - 1, n);
return rec_uniquePaths(m-1, n) + rec_uniquePaths(m, n - 1);
}
【】有障碍
c# S.Getlength(0)表示行数
class Solution {
public int uniquePathsWithObstacles(int[][] obstacleGrid) {
int R = obstacleGrid.length;
int C = obstacleGrid[0].length;
// If the starting cell has an obstacle, then simply return as there would be
// no paths to the destination.
if (obstacleGrid[0][0] == 1) {
return 0;
}
// Number of ways of reaching the starting cell = 1.
obstacleGrid[0][0] = 1;
// Filling the values for the first column
for (int i = 1; i < R; i++) {
obstacleGrid[i][0] = (obstacleGrid[i][0] == 0 && obstacleGrid[i - 1][0] == 1) ? 1 : 0;
}
// Filling the values for the first row
for (int i = 1; i < C; i++) {
obstacleGrid[0][i] = (obstacleGrid[0][i] == 0 && obstacleGrid[0][i - 1] == 1) ? 1 : 0;
}
// Starting from cell(1,1) fill up the values
// No. of ways of reaching cell[i][j] = cell[i - 1][j] + cell[i][j - 1]
// i.e. From above and left.
for (int i = 1; i < R; i++) {
for (int j = 1; j < C; j++) {
if (obstacleGrid[i][j] == 0) {
obstacleGrid[i][j] = obstacleGrid[i - 1][j] + obstacleGrid[i][j - 1];
} else {
obstacleGrid[i][j] = 0;
}
}
}
// Return value stored in rightmost bottommost cell. That is the destination.
return obstacleGrid[R - 1][C - 1];
}
}
单元最短路径
https://blog.csdn.net/ccnuacmhdu/article/details/78765648
串
https://leetcode-cn.com/problems/valid-palindrome/
【】将所给字符串筛选后判断是否为回文串
https://leetcode-cn.com/problems/longest-palindrome/
找出字符串中每个字符出现的次数
若字符出现次数为奇数次,出现的次数减去1则为可用于构造回文串的字符数。若出现的次数为偶数次,出现次数则为可用于构造回文串的字符数
若存在奇数次字符,则最终结果再+1,因为奇数字符可放一个在最中间
https://leetcode-cn.com/problems/find-all-anagrams-in-a-string/
【】在串中找出所有与所给串的长度相同的串
https://leetcode-cn.com/problems/repeated-substring-pattern/
【】将字符串加起来,判断中间是否会存在这个字符串