Leetcode刷题之旅
chenxli23
记录下一点一滴的成长
展开
-
Leetcode 跳跃游戏
5. 跳跃游戏5给你一个整数数组arr 和一个整数d 。每一步你可以从下标i跳到:i + x,其中i + x < arr.length且0 < x <= d。i - x,其中i - x >= 0且0 < x <= d。除此以外,你从下标i 跳到下标 j需要满足:arr[i] > arr[j]且 arr[i] > arr[k],其中下标k是所有 i到 j之间的数字(更正式的,min(i, j) < k...原创 2020-10-04 16:28:46 · 251 阅读 · 0 评论 -
leectode 石子游戏
1. 石子游戏题目描述:Alex and Lee play a game with piles of stones. There are an even number ofpilesarranged in a row, and each pile has a positive integer number of stonespiles[i].The objective of the game is to end with the moststones. The total numbe...原创 2020-08-24 02:00:13 · 493 阅读 · 0 评论 -
Leetcode 第32场双周赛
只做出3道题,记录一下代码~5468.第 k 个缺失的正整数给你一个严格升序排列的正整数数组arr和一个整数k。请你找到这个数组里第k个缺失的正整数。示例 1:输入:arr = [2,3,4,7,11], k = 5输出:9解释:缺失的正整数包括 [1,5,6,8,9,10,12,13,...] 。第 5 个缺失的正整数为 9 。示例 2:输入:arr = [1,2,3,4], k = 2输出:6解释:缺失的正整数包括 [5,6,7,...] 。第...原创 2020-08-09 00:45:13 · 304 阅读 · 0 评论 -
Leetcode 周赛186
1.分割字符串的最大得分题目描述:给你一个由若干 0 和 1 组成的字符串 s ,请你计算并返回将该字符串分割成两个 非空 子字符串(即左 子字符串和 右 子字符串)所能获得的最大得分。「分割字符串的得分」为 左 子字符串中 0 的数量加上 右 子字符串中 1 的数量。示例 1:输入:s = "011101"输出:5解释:将字符串 s 划分为两个非空子字符串的...原创 2020-04-26 18:04:43 · 377 阅读 · 0 评论 -
Leetcode 93. Restore IP Addresses
题目描述:Given a string containing only digits, restore it by returning all possible valid IP address combinations.Example:Input: "25525511135"Output: ["255.255.11.135", "255.255.111.35"]程序:c...原创 2020-04-20 23:42:34 · 170 阅读 · 1 评论 -
Leetcode 252.Contiguous Array
题目描述:Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1.Example 1:Input: [0,1]Output: 2Explanation: [0, 1] is the longest contiguous subarray ...原创 2020-04-20 17:19:34 · 182 阅读 · 0 评论 -
LeetCode 183周赛
5376. Minimum Subsequence in Non-Increasing Order题目描述:Given the array nums, obtain a subsequence of the array whose sum of elements is strictly greater than the sum of the nonincluded elements in...原创 2020-04-05 14:37:59 · 298 阅读 · 1 评论 -
42. Trapping Rain Water
题意描述:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.The above elevation map is represented b...原创 2020-04-04 11:10:57 · 184 阅读 · 0 评论 -
Leetcode周赛180
1380.Lucky Numbers in a MatrixGiven am * nmatrix ofdistinctnumbers, return all lucky numbers in thematrix inanyorder.A lucky number is an element of the matrix such that it is the minim...原创 2020-03-22 21:12:06 · 287 阅读 · 0 评论 -
137. Single Number II
题目描述:Given anon-emptyarray of integers, every element appearsthreetimes except for one, which appears exactly once. Find that single one.Note:Your algorithm should have a linear runtime comp...原创 2020-03-03 01:06:11 · 164 阅读 · 0 评论 -
40. Combination Sum II
题目描述:Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations incandidateswhere the candidate numbers sums totarget.Each number incandida...原创 2020-01-03 22:26:14 · 135 阅读 · 0 评论 -
114. Flatten Binary Tree to Linked List
题目描述:Given a binary tree, flatten it to a linked list in-place.For example, given the following tree: 1 / \ 2 5 / \ \3 4 6The flattened tree should look like:1 \ 2...原创 2019-12-31 01:52:08 · 179 阅读 · 0 评论 -
113. Path Sum II
题目:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.Note:A leaf is a node with no children.Example:Given the below binary tree andsum = 2...原创 2019-12-06 00:05:41 · 179 阅读 · 0 评论 -
129. Sum Root to Leaf Numbers
题目:;Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which represents the number123.Find th...原创 2019-12-05 00:56:35 · 155 阅读 · 0 评论 -
501. Find Mode in Binary Search Tree
题目描述:Given a binary search tree (BST) with duplicates, find all themode(s)(the most frequently occurred element) in the given BST.Assume a BST is defined as follows:The left subtree of a node ...原创 2019-11-29 01:07:42 · 200 阅读 · 0 评论 -
543. Diameter of Binary Tree
题目描述:Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of thelongestpath between any two nodes in a tree. This path may o...原创 2019-11-27 01:13:47 · 162 阅读 · 0 评论 -
326. Power of Three
题目描述:Given an integer, write a function to determine if it is a power of three.Example 1:Input: 27Output: trueExample 2:Input: 0Output: falseExample 3:Input: 9Output: trueExampl...原创 2019-10-27 23:30:40 · 126 阅读 · 0 评论 -
257. Binary Tree Paths
题目描述:Given a binary tree, return all root-to-leaf paths.Note:A leaf is a node with no children.Example:Input: 1 / \2 3 \ 5Output: ["1->2->5", "1->3"]Explanation: ...原创 2019-10-20 18:01:11 · 130 阅读 · 0 评论 -
205. Isomorphic Strings
题目描述:Given two stringssandt, determine if they are isomorphic.Two strings are isomorphic if the characters inscan be replaced to gett.All occurrences of a character must be replaced with a...原创 2019-10-17 00:25:11 · 176 阅读 · 0 评论 -
203. Remove Linked List Elements
题目描述:Remove all elements from a linked list of integers that have valueval.Example:Input: 1->2->6->3->4->5->6, val = 6Output: 1->2->3->4->5程序:class Solutio...原创 2019-10-16 23:55:27 · 123 阅读 · 0 评论 -
190. Reverse Bits
题目描述:Reverse bits of a given 32 bits unsigned integer.Example 1:Input: 00000010100101000001111010011100Output: 00111001011110000010100101000000Explanation: The input binary string 00000010...原创 2019-10-15 11:11:41 · 131 阅读 · 0 评论 -
189. Rotate Array
题目描述:Given an array, rotate the array to the right byksteps, wherekis non-negative.Example 1:Input: [1,2,3,4,5,6,7] and k = 3Output: [5,6,7,1,2,3,4]Explanation:rotate 1 steps to the righ...转载 2019-10-14 11:06:04 · 114 阅读 · 0 评论 -
169. Majority Element
题目描述:Given an array of sizen, find the majority element. The majority element is the element that appearsmore than⌊ n/2 ⌋times.You may assume that the array is non-empty and the majority eleme...原创 2019-10-12 12:41:00 · 121 阅读 · 0 评论 -
168. Excel Sheet Column Title
题目描述:Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA ...原创 2019-10-12 12:35:49 · 115 阅读 · 0 评论 -
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.Your algorithm’s runtime complexity must be in the order of O(log n).If...原创 2019-09-26 00:47:47 · 106 阅读 · 0 评论 -
33. Search in Rotated Sorted Array
题目描述:Suppose 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]).You are given a target value to search. If...原创 2019-09-15 22:10:38 · 128 阅读 · 0 评论 -
24. Swap Nodes in Pairs
题目描述:Given alinked list, swap every two adjacent nodes and return its head.You may not modify the values in the list's nodes, only nodes itself may be changed.Example:Given 1->2->3-&...原创 2019-09-03 23:55:51 · 119 阅读 · 0 评论 -
12. Integer to Roman
题目描述:Roman numerals are represented by seven different symbols:I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2019-09-03 14:55:55 · 163 阅读 · 0 评论 -
3. Longest Substring Without Repeating Characters
题目描述:Given a string, find the length of the longest substring without repeating characters.Example 1:Input: "abcabcbb"Output: 3Explanation: The answer is "abc", with the length of 3.Example...原创 2019-09-03 14:16:23 · 161 阅读 · 0 评论 -
2. Add Two Numbers
题目描述:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and r...原创 2019-09-03 14:12:30 · 153 阅读 · 0 评论 -
1. Two Sum
题目描述:Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use th...原创 2019-09-03 14:10:21 · 131 阅读 · 0 评论 -
41. First Missing Positive
题目描述:Given an unsorted integer array, find the smallest missingpositive integer.Example 1:Input: [1,2,0]Output: 3Example 2:Input: [3,4,-1,1]Output: 2Example 3:Input: [7,8,9,11,12...原创 2019-09-27 00:37:03 · 125 阅读 · 0 评论 -
48. Rotate Image
题目描述:You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the imagein-place, which means you have to modify the input 2D m...原创 2019-09-30 00:34:03 · 124 阅读 · 0 评论 -
54. Spiral Matrix
题目描述:Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in spiral order.Example 1:Input:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]Output: [1,2,3,6,9,8,7...原创 2019-10-03 00:28:33 · 146 阅读 · 0 评论 -
66. Plus One
题目描述:Given anon-emptyarray of digitsrepresenting a non-negative integer, plus one to the integer.The digits are stored such that the most significant digit is at the head of the list, and each ...原创 2019-10-04 00:01:50 · 125 阅读 · 0 评论 -
83. Remove Duplicates from Sorted List
题目描述:Given a sorted linked list, delete all duplicates such that each element appear onlyonce.Example 1:Input: 1->1->2Output: 1->2Example 2:Input: 1->1->2->3->3Out...原创 2019-10-04 00:14:02 · 114 阅读 · 0 评论 -
88. Merge Sorted Array
题目描述:Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:The number of elements initialized innums1andnums2aremandnrespectively. You may ass...原创 2019-10-05 00:35:05 · 118 阅读 · 0 评论 -
136. Single Number
题目描述:Given anon-emptyarray of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it wit...原创 2019-10-07 09:55:26 · 118 阅读 · 0 评论 -
141. Linked List Cycle
题目描述:Given a linked list, determine if it has a cycle in it.To represent a cycle in the given linked list, we use an integerposwhich represents the position (0-indexed)in the linked list where ...原创 2019-10-07 10:23:29 · 156 阅读 · 0 评论 -
160. Intersection of Two Linked Lists
题目描述:Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:begin to intersect at node c1.Example 1:...原创 2019-10-11 11:28:28 · 200 阅读 · 0 评论