- 博客(122)
- 收藏
- 关注
原创 leetcode #92Reverse Linked List II
Reverse a linked list from position m to n. Do it in one-pass.Note: 1 ≤ m ≤ n ≤ length of list.Example:Input: 1->2->3->4->5->NULL, m = 2, n = 4Output: 1->4->3->2->5->...
2020-04-17 05:56:59 156 1
原创 leetcode #88merge sort array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:The number of elements initialized in nums1 and nums2 are m and n respectively.You may assume that n...
2020-04-16 14:17:17 116
原创 leetcode#74Search 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 i...
2020-04-14 11:03:09 129
原创 leetcode#70 climbing stair
ou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a positive in...
2020-04-14 05:49:21 111
原创 leetcode#69 sqrt()
利用二分搜索, 从1到x搜索if(x<=1) {return x;} int begin = 1; int end = x; int middle = 0; while(begin<=end) { middle = begin + (end - begin)/2; //不要写成middle*m...
2020-04-14 05:36:30 94
原创 leetcode #58 length of last word
Length of Last WordEasy5582203Add to ListShareGiven a string s consists of upper/lower-case alphabets and empty space characters ’ ', return the length of last word (last word means the last a...
2020-04-08 04:07:10 87
原创 leetcode 56 merge intervals
Merge IntervalsMedium3494257Add to ListShareGiven a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Expl...
2020-04-08 03:38:05 119
原创 leetcode # 49 group anagrams
Given an array of strings, group anagrams together.Example:Input: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”],Output:[[“ate”,“eat”,“tea”],[“nat”,“tan”],[“bat”]]Note:All inputs will be in lowe...
2020-04-04 02:54:22 100
原创 leetcode#49. Group Anagrams
Given an array of strings, group anagrams together.Example:Input: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”],Output:[[“ate”,“eat”,“tea”],[“nat”,“tan”],[“bat”]]Note:All inputs will be in lowe...
2020-04-04 02:16:56 84
原创 leetcode 48 # rotate image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the image in-place, which means you have to modify the input 2D matrix dire...
2020-04-03 04:39:10 83
原创 leetcode #43 Multiply Strings
Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.Example 1:Input: num1 = “2”, num2 = “3”Output: “6”Example 2:...
2020-04-03 03:20:35 100
原创 leetcode回溯法总结
第二遍做leetcode 中的回溯法, 发现不光没有更好的理解,甚至遗忘了很多。 所以今天觉得做一篇有关回溯法的总结首先,回溯法的基本思想:从一条路往前走,能进则进,不能进则退回,换一条路再试回溯法的基本定义和概念首先要明确下面三个概念1约束函数:约束函数是根据题意定出, 通过描述合法解的一般特征用于去除不合法的解,从而避免继续搜索出这个不合法解的剩余部分2状态空间树状态空间树是一个对...
2020-04-02 04:14:49 167
原创 leetcode#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 found in...
2020-03-26 06:50:04 78
原创 leetcode #26 Remove Duplicates from Sorted Array
Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this by modifyin...
2020-03-24 06:47:52 103
原创 Leetcode #24. Swap Nodes in Pairs java
Given a linked 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->4, you sho...
2020-03-24 06:23:59 80
原创 leetcode #17. Letter Combinations of a Phone Number
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is give...
2020-03-20 09:01:55 103
原创 leetcode#14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string “”.Example 1:Input: [“flower”,“flow”,“flight”]Output: “fl...
2020-03-18 13:02:06 112
原创 leetcode#150. Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Note:Division between two integers sho...
2020-03-07 10:48:49 70
原创 #148. Sort List
Sort a linked list in O(n log n) time using constant space complexity.Example 1:Input: 4->2->1->3Output: 1->2->3->4Example 2:Input: -1->5->3->4->0Output: -1->0-&...
2020-03-07 05:57:07 76
原创 leetcode #147. Insertion Sort List
Sort a linked list using insertion sort.A graphical example of insertion sort. The partial sorted list (black) initially contains only the first element in the list.With each iteration one element (...
2020-03-06 14:49:19 102
原创 leetcode #143. Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You may not modify the values in the list’s nodes, only nodes itself may be changed.Example 1:Given 1->2->...
2020-03-06 04:02:44 89
原创 leetcode#142. Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.To represent a cycle in the given linked list, we use an integer pos which represents the position (0-in...
2020-03-05 08:08:23 113
原创 leetcode #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 integer pos which represents the position (0-indexed) in the linked list where tail con...
2020-03-05 06:52:13 93
原创 leetcode #138. Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.The Linked List is represented in th...
2020-03-05 04:14:26 142
原创 leetcode #136. Single Number
Given a non-empty array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without usin...
2020-03-04 13:55:31 93
原创 leetcode #134. Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its n...
2020-03-04 12:31:50 173
原创 leetcode #131 Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.Example:Input: “aab”Output:[[“aa”,“b”],[“a”,“a”,“b”]]...
2020-03-04 12:01:58 99
原创 leetcode #122. Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one...
2020-03-04 04:30:15 86
原创 letcode#119. Pascal's Triangle II
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal’s triangle.Note that the row index starts from 0.In Pascal’s triangle, each number is the sum of the two numbers dir...
2020-03-03 07:36:29 74
原创 leetcode#116 Populating Next Right Pointers in Each Node
You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:struct Node {int val;Node *left;Node *ri...
2020-02-29 05:25:42 90
原创 leetcode #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:123456知识点stack 先进先出pop ...
2020-02-28 13:49:42 87
原创 leetcode#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 and sum = 22, 5 ...
2020-02-28 04:19:27 100
原创 leetcode #111. Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Note: A leaf is a node with no children....
2020-02-27 07:45:25 98
原创 leetcode#110. Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as:a binary tree in which the left and right subtrees of every node differ in heigh...
2020-02-27 06:48:14 95
原创 leetcode#109. Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the d...
2020-02-26 13:47:17 79
原创 leetcode#108. Convert Sorted Array to Binary Search Tree
二分查找中的问题循环条件为什么不是 (l<r)第一,如果数组长度为1的话,不管查找什么都会恒定的返回-1,这显然是错的。第二,当l + 1 = r的时候,mid=l,如果此时A[mid]小于target执行l=mid+1=r,再次循环时候while条件不满足,将退出循环,但是A[right]可能==target。考虑[3,5] k=5的情况,这时候会返nick大神讲解看了视频发现了...
2020-02-26 07:45:08 102
原创 leetcode#102Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7],3/ 9 20/ 15 7retu...
2020-02-26 06:34:22 74
原创 leetcode #107. Binary Tree Level Order Traversal II
Binary Tree Level Order Traversal IIEasy1039186Add to ListShareGiven a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level fro...
2020-02-26 06:33:46 121
原创 leetcode#105 Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.For example, givenpreorder = [3,9,20,15,7]inorder = [9,3,15,...
2020-02-26 06:00:38 75
原创 leetcode #79. Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically ne...
2020-02-26 05:25:46 95
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人