网站首页 站内搜索

搜索结果

查询Tags标签: right,共有 1521条记录
  • 54. 螺旋矩阵(c++)

    class Solution { public:vector<int> spiralOrder(vector<vector<int>>& matrix) {if(matrix.size() == 0 && matrix[0].size() == 0){return {{}};}int left = 0, right = matrix[0].size()-1, top = 0, bottom = matrix.size()-1;vector…

    2022/2/6 1:13:39 人评论 次浏览
  • 八大排序归并排序

    public class MergeSort {public static void main(String[] args) {int[] arr = new int[]{2,5,6,4,8,5,4,1,22,3,45};merge(arr,0,arr.length-1);System.out.println(Arrays.toString(arr));}public static void merge(int arr[],int left,int right) {if(left ==right)…

    2022/2/5 23:16:13 人评论 次浏览
  • 在数组中查找元素第一个与最后一个的位置

    1.当数组无序时: 双指针+递归 class Solution {public int[] searchRange(int[] nums, int target) {//空数组,直接返回if(nums.length == 0){return new int[]{-1,-1};}//初始左指针,指向第一个元素int left = 0;//初试右指针,指向最后一个元素int right = nums.lengt…

    2022/2/5 23:16:06 人评论 次浏览
  • 数组中的第K个最大元素(java go)

    数组中的第K个最大元素 核心:快速排序,扩展只排多少个。 java public int findKthLargest(int[] nums, int k) {if (nums.length < 1 || k < 1 || k > nums.length) {return -1;}return partition(nums, 0, nums.length - 1, nums.length - k); }public int pa…

    2022/2/5 20:13:57 人评论 次浏览
  • 插值查找算法

    差值查找算法与二分查找算法类似,主要就是mid的值不是(left=right)/2,而是mid=low+(high-low)*(key-arr[low])/(arr[high]-arr[low]);其中有两点不同: 1,int mid=low+ (right-left) * (findVal-arr[left]) / (arr[right] - arr[left]) 2,由于mid公式里面自适应加入了findV…

    2022/2/5 17:14:05 人评论 次浏览
  • LC-恢复二叉搜索树(JavaScript实现)

    /** @lc app=leetcode.cn id=99 lang=javascript** [99] 恢复二叉搜索树*/// @lc code=start /*** Definition for a binary tree node.* function TreeNode(val, left, right) {* this.val = (val===undefined ? 0 : val)* this.left = (left===undefined ? nu…

    2022/2/5 17:14:05 人评论 次浏览
  • 算法【树】 | 【栈用法】如何快速搞懂前序、中序、后序遍历?

    文章目录 一、树的遍历1.1 先序遍历1.2 中序遍历1.3 后序遍历1.4 代码一、树的遍历

    2022/2/5 17:12:26 人评论 次浏览
  • LC-验证二叉搜索树(JavaScript实现)

    /** @lc app=leetcode.cn id=98 lang=javascript** [98] 验证二叉搜索树*/// @lc code=start /*** Definition for a binary tree node.* function TreeNode(val, left, right) {* this.val = (val===undefined ? 0 : val)* this.left = (left===undefined ? nu…

    2022/2/5 14:43:03 人评论 次浏览
  • 力扣字符串专题:第五天,拜年回来了,继续肝

    离开力扣两三天,手就痒痒啊!完了,彻底中毒了,哈哈哈!!! 今日第一题:力扣第3题 解题思路: 首先肯定想到的是暴力解法,双指针,里外循环一起走,但是这个时间复杂度为O(n2),为了减少时间复杂度,我们让内循环(左指针)不回头的遍历,拿到一个ans的字符子串长度,…

    2022/2/5 6:15:04 人评论 次浏览
  • 543. Diameter of Binary Tree

    This is a Post Order binary tree problem. For every node, we need to know its left trees maximal diameter and its right trees maximal diameter, and add left and right, we can get a sub-trees maximal diameter, we just find the maximum of all node, the …

    2022/2/5 6:12:24 人评论 次浏览
  • Leetcode 617. 合并二叉树 遍历二叉树

    地址 https://leetcode-cn.com/problems/merge-two-binary-trees/ 给你两棵二叉树: root1 和 root2 。 想象一下,当你将其中一棵覆盖到另一棵之上时,两棵树上的一些节点将会重叠(而另一些不会)。 你需要将这两棵树合并成一棵新二叉树。 合并的规则是:如果两个节点重…

    2022/2/4 23:43:53 人评论 次浏览
  • 力扣剑指offer第17天 树

    47)二叉树剪枝 class Solution { public:TreeNode* pruneTree(TreeNode* root) {if(root->left) root->left = pruneTree(root->left);if(root->right) root->right = pruneTree(root->right);if(root->left==nullptr && root->right==n…

    2022/2/4 23:22:32 人评论 次浏览
  • 【C++】二叉搜索树

    今天我们来讲一种特殊的二叉树,二叉搜索树。学好二叉搜索树,有助于我们之后对map和set的理解与掌握。目录 二叉搜索树概念二叉搜索树操作1. 查找2. 插入3. 删除 二叉搜索树实现二叉搜索树应用二叉搜索树性能分析二叉搜索树概念 二叉搜索树又称二叉排序树,它或者是一棵空…

    2022/2/4 17:46:12 人评论 次浏览
  • 力扣算法学习day15-1

    文章目录 力扣算法学习day15-1654-最大二叉树题目代码实现 617-合并二叉树题目代码实现已复习 24-两两交换链表中的结点力扣算法学习day15-1 654-最大二叉树 题目代码实现 /*** Definition for a binary tree node.* public class TreeNode {* int val;* TreeNode…

    2022/2/4 12:12:51 人评论 次浏览
  • 【MySQL】关键字及运算符官方文档及笔记

    前言 写SQL题经常用,遇到的在这里记录一下 1. join on 和 where 的条件区别 MySQL5.7 join 相关文档 1.1 用 left join 取代 right joinRIGHT JOIN works analogously to LEFT JOIN. To keep code portable across databases, it is recommended that you use LEFT JOIN …

    2022/2/4 2:14:10 人评论 次浏览
扫一扫关注最新编程教程