题目: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example 1: nums1 = [1, 3] nums2 = [2] The median is 2.0 Example 2: nums1 =…
Given an input string, reverse the string word by word. For example, Given s = "the sky is blue", return "blue is sky the". click to show clarification. Clarification: What constitutes a word? A sequence of non-space characters constit…
题目: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word does not exist, return 0. Note: A word is defined as a character sequence consists of non-space…
题目: Toeplitz Matrix A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Now given an M x N matrix, return True if and only if the matrix is Toeplitz. Example 1: Input: matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]Out…
Suppose a sorted array 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 no duplicate exists in the array. 题解:就是找数组中第一个“下凹”的地方,可以遍历,不过也可以用二分法,速度更快. 特别注意边界的处理…
4. Median of Two Sorted Arrays There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example 1: nums1 = [, ] nums2 = [] The median i…
本文接着上一篇文章<LeetCode刷题总结-数组篇(上)>,继续讲第二个常考问题:矩阵问题. 矩阵也可以称为二维数组.在LeetCode相关习题中,作者总结发现主要考点有:矩阵元素的遍历.矩阵位置的旋转.矩阵行或列次序的交换.空间复杂度为O(1)等.本期共12道题,2道简单题,8道中等题,2道困难题. 例1是杨辉三角的一个延申题,是一道非常经典的矩阵习题,本题理想解法是动态规划,但是也可以采用递归来求解. 例2是一道顺时针访问矩阵元素的习题,在不少面试题中有见到. 例3.例4和例5则强调如果…
分治算法篇 # 题名 刷题 通过率 难度 4 两个排序数组的中位数 C#LeetCode刷题之#4-两个排序数组的中位数(Median of Two Sorted Arrays)-该题未达最优解 30.9% 困难 23 合并K个排序链表   39.4% 困难 53 最大子序和 C#LeetCode刷题之#53-最大子序和(Maximum Subarray)-该题包含分治讨论 38.4% 简单 169 求众数 C#LeetCode刷题之#169-求众数(Majority Element) 52.3…
二分查找篇 # 题名 刷题 通过率 难度 4 两个排序数组的中位数 C#LeetCode刷题之#4-两个排序数组的中位数(Median of Two Sorted Arrays)-该题未达最优解 30.8% 困难 29 两数相除   15.3% 中等 33 搜索旋转排序数组   32.6% 中等 34 在排序数组中查找元素的第一个和最后一个位置   31.9% 中等 35 搜索插入位置 C#LeetCode刷题之#35-搜索插入位置(Search Insert Position) 40.0% 简…
数组篇 # 题名 刷题 通过率 难度 1 两数之和 C#LeetCode刷题之#1-两数之和(Two Sum) 43.1% 简单 4 两个排序数组的中位数 C#LeetCode刷题之#4-两个排序数组的中位数(Median of Two Sorted Arrays)-该题未达最优解 30.1% 困难 11 盛最多水的容器 C#LeetCode刷题之#11-盛最多水的容器(Container With Most Water) 37.9% 中等 15 三数之和 C#LeetCode刷题之#15-三数…