文章 2023-11-01 来自:开发者社区

Leetcode 4. Median of Two Sorted Arrays

题目链接 Leetcode 4. Median of Two Sorted Arrays  题目描述很简单,就是找到两个有序数组合并后的中位数,要求时间复杂度O(log (m+n))。  如果不要去时间复杂度,很容易就想到了归并排序,归并排序的时间复杂度是O(m+n),空间复杂度也是O(m+n),不满足题目要求,其实我开始也不知道怎么做,后来看了别人的博客才知道有个二分法求两....

文章 2023-11-01 来自:开发者社区

Leetcode Find Minimum in Rotated Sorted Array 题解

Leetcode Find Minimum in Rotated Sorted Array题目大意:     对一个有序数组翻转, 就是随机取前K个数,移动到数组的后面,然后让你找出最小的那个数,注意,K有可能是0,也就是没有翻转。     毫无疑问,遍历一次肯定可以找到,但这样时间复杂度是O(n),如果你在面试的时候遇到这样的问题,你这样回答面试官肯定不....

文章 2023-01-11 来自:开发者社区

LeetCode 167 Two Sum II - Input array is sorted(输入已排序数组,求其中两个数的和等于给定的数)

Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers s....

文章 2023-01-08 来自:开发者社区

LeetCode 108. 将有序数组转换为二叉搜索树 Convert Sorted Array to Binary Search Tree

LeetCode 108. 将有序数组转换为二叉搜索树 Convert Sorted Array to Binary Search TreeTable of Contents一、中文版二、英文版三、My answer四、解题报告一、中文版将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索树。本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1。示例:给....

文章 2023-01-07 来自:开发者社区

LeetCode 88. 合并两个有序数组 Merge Sorted Array

LeetCode 88. 合并两个有序数组 Merge Sorted ArrayTable of Contents一、中文版二、英文版三、My answer四、解题报告一、中文版给你两个有序整数数组 nums1 和 nums2,请你将 nums2 合并到 nums1 中,使 nums1 成为一个有序数组。 说明:初始化 nums1 和 nums2 的元素数量分别为 m 和 n 。你可以....

文章 2023-01-07 来自:开发者社区

LeetCode 21. 合并两个有序链表 Merge Two Sorted Lists

LeetCode 21. 合并两个有序链表 Merge Two Sorted ListsTable of Contents一、中文版二、英文版三、My answer四、解题报告一、中文版将两个升序链表合并为一个新的升序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。  示例:输入:1->2->4, 1->3->4输出:1->1->2-&am...

文章 2023-01-07 来自:开发者社区

LeetCode 5340. 统计有序矩阵中的负数 Count Negative Numbers in a Sorted Matrix

LeetCode 5340. 统计有序矩阵中的负数 Count Negative Numbers in a Sorted MatrixTable of Contents中文版:英文版:My answer:解题报告:中文版:给你一个 m * n 的矩阵 grid,矩阵中的元素无论是按行还是按列,都以非递增顺序排列。  请你统计并返回 grid 中 负数 的数目。示例 1:输入:grid ....

文章 2023-01-05 来自:开发者社区

LeetCode 378. Kth S Element in a Sorted Matrix

DescriptionGiven a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.Note that it is the kth smallest element in the sorted or....

LeetCode 378. Kth S Element in a Sorted Matrix
文章 2023-01-05 来自:开发者社区

LeetCode Find Minimum in Rotated Sorted Array II

DescriptionSuppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).Find the minimum element.The array may co....

LeetCode Find Minimum in Rotated Sorted Array II
文章 2023-01-05 来自:开发者社区

LeetCode 153. Find Minimum in Rotated Sorted Array

DescriptionSuppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).Find the minimum element.You may assume n....

LeetCode 153. Find Minimum in Rotated Sorted Array

本页面内关键词为智能算法引擎基于机器学习所生成,如有任何问题,可在页面下方点击"联系我们"与我们沟通。

算法编程

开发者社区在线编程频道官方技术圈。包含算法资源更新,周赛动态,每日一题互动。

+关注