leetcode刷题笔记
文章平均质量分 61
Jeffrey_yh
这个作者很懒,什么都没留下…
展开
-
167. Two Sum II - Input array is sorted
刷题笔记167. Two Sum II - Input array is sorted题目Given an array of integers numbers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.Return the indices of the two numbers (1-indexed) as an intege原创 2021-05-05 23:55:28 · 98 阅读 · 0 评论 -
162. Find Peak Element
刷题笔记162. Find Peak Element题目A peak element is an element that is strictly greater than its neighbors.Given an integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks.You原创 2021-05-05 17:43:08 · 88 阅读 · 0 评论 -
154. Find Minimum in Rotated Sorted Array II
刷题笔记154. Find Minimum in Rotated Sorted Array II题目Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,4,4,5,6,7] might become:[4,5,6,7,0,1,4] if it was rotated 4 times.[0,1,4,4,5,原创 2021-05-04 23:22:33 · 64 阅读 · 0 评论 -
153. Find Minimum in Rotated Sorted Array
刷题笔记153. Find Minimum in Rotated Sorted Array题目Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become:[4,5,6,7,0,1,2] if it was rotated 4 times.[0,1,2,4,5,6,7原创 2021-05-04 20:34:30 · 47 阅读 · 0 评论 -
81. Search in Rotated Sorted Array II
刷题笔记81. Search in Rotated Sorted Array II题目There is an integer array nums sorted in non-decreasing order (not necessarily with distinct values).Before being passed to your function, nums is rotated at an unknown pivot index k (0 <= k < nums.lengt原创 2021-05-04 15:47:41 · 77 阅读 · 0 评论 -
33. Search in Rotated Sorted Array
刷题笔记33. Search in Rotated Sorted Array题目There is an integer array nums sorted in ascending order (with distinct values).Prior to being passed to your function, nums is rotated at an unknown pivot index k (0 <= k < nums.length) such that the resul原创 2021-05-04 09:42:39 · 52 阅读 · 0 评论 -
240. Search a 2D Matrix II
刷题笔记240. Search a 2D Matrix II题目Write an efficient algorithm that searches for a target value in an m x n integer matrix. The matrix has the following properties:Integers in each row are sorted in ascending from left to right.Integers in each column a原创 2021-05-02 23:31:19 · 88 阅读 · 0 评论 -
34. Find First and Last Position of Element in Sorted Array
刷题笔记34. Find First and Last Position of Element in Sorted Array题目Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.If target is not found in the array, return [-1, -1].Follow up: C原创 2021-05-02 22:54:02 · 49 阅读 · 0 评论 -
74. Search a 2D Matrix
刷题笔记74. Search a 2D Matrix题目Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each row is greater than the last i原创 2021-05-01 23:27:38 · 75 阅读 · 0 评论 -
69. Sqrt(x)
刷题笔记69. Sqrt(x)题目Given a non-negative integer x, compute and return the square root of x.Since the return type is an integer, the decimal digits are truncated, and only the integer part of the result is returned.思路用二分法思想,开跟的数一定在1和x之间(除0之外),那么这是一个在1原创 2021-05-01 23:18:51 · 65 阅读 · 0 评论 -
50. Pow(x, n)
刷题笔记50. Pow(x, n)题目Implement pow(x, n), which calculates x raised to the power n (i.e., xn).思路我原本的思路是常规的递归,递归n - 1。其实原理上没有问题,但是实际在很大幂次的时候会导致消耗内存过大,导致栈溢出。如下class Solution { public double myPow(double x, int n) { if (n == 0) return 1;原创 2021-05-01 19:07:31 · 86 阅读 · 0 评论 -
35. Search Insert Position
刷题笔记35. Search Insert Position题目Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.思路我的思路比较繁琐,首先是判断如果target大于最大的,就直接返回最大坐标+1;原创 2021-05-01 17:45:25 · 88 阅读 · 0 评论 -
15. 3Sum
刷题笔记15. 3Sum题目Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.Notice that the solution set must not contain duplicate triplets.思路又是一道没自己做出来的原创 2021-04-30 23:33:54 · 80 阅读 · 1 评论 -
11. Container With Most Water
刷题笔记11. Container With Most Water题目Given n non-negative integers a1, a2, …, an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of the line i is at (i, ai) and (i, 0). Find two lines, which, t原创 2021-04-30 18:30:00 · 97 阅读 · 1 评论 -
1561. Maximum Number of Coins You Can Get
刷题笔记1561. Maximum Number of Coins You Can Get题目There are 3n piles of coins of varying size, you and your friends will take piles of coins as follows:In each step, you will choose any 3 piles of coins (not necessarily consecutive).Of your choice, Alice原创 2021-04-30 16:54:48 · 114 阅读 · 1 评论 -
1. Two Sum
刷题笔记1.Two Sum题目Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.You may assume that each input would have exactly one solution, and you may not use the same element twice.You can原创 2021-04-28 21:28:38 · 61 阅读 · 0 评论 -
1370. Increasing Decreasing String
刷题笔记1370. Increasing Decreasing String题目(这是一道虚假的easy题)Given a string s. You should re-order the string using the following algorithm:Pick the smallest character from s and append it to the result.Pick the smallest character from s which is greater tha原创 2021-04-27 18:36:53 · 99 阅读 · 0 评论 -
1630. Arithmetic Subarrays
刷题笔记1630. Arithmetic Subarrays题目A sequence of numbers is called arithmetic if it consists of at least two elements, and the difference between every two consecutive elements is the same. More formally, a sequence s is arithmetic if and only if s[i+1] -原创 2021-04-27 16:30:34 · 92 阅读 · 0 评论 -
1305. All Elements in Two Binary Search Trees
刷题笔记1305. All Elements in Two Binary Search Trees题目Given two binary search trees root1 and root2.Return a list containing all the integers from both trees sorted in ascending order.思路首先想到要把两个树中的元素全部取到一个list中,然后对这个list进行排序并返回即可。取树元素可以利用递归思想,对两个树分别递原创 2021-04-26 22:04:07 · 68 阅读 · 0 评论 -
1329. Sort the Matrix Diagonally
刷题笔记1329. Sort the Matrix Diagonally题目A matrix diagonal is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix’s end. For example, the matrix dia原创 2021-04-25 12:57:17 · 81 阅读 · 0 评论 -
1637. Widest Vertical Area Between Two Points Containing No Points
刷题笔记1637. Widest Vertical Area Between Two Points Containing No Points题目Given n points on a 2D plane where points[i] = [xi, yi], Return the widest vertical area between two points such that no points are inside the area.A vertical area is an area of fi原创 2021-04-24 19:37:43 · 126 阅读 · 0 评论 -
1528. Shuffle String
刷题笔记1528. Shuffle StringGiven a string s and an integer array indices of the same length.The string s will be shuffled such that the character at the ith position moves to indices[i] in the shuffled string.Return the shuffled string.思路首先这个问题将涉及三个数据原创 2021-04-23 22:03:37 · 70 阅读 · 0 评论 -
1833. Maximum Ice Cream bars
刷题日记1833. Maximum Ice Cream barsIt is a sweltering summer day, and a boy wants to buy some ice cream bars.At the store, there are n ice cream bars. You are given an array costs of length n, where costs[i] is the price of the ith ice cream bar in coins.原创 2021-04-23 21:13:09 · 215 阅读 · 0 评论