![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
zyp7355
这个作者很懒,什么都没留下…
展开
-
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 · 100 阅读 · 0 评论 -
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 · 113 阅读 · 0 评论 -
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 · 91 阅读 · 0 评论 -
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 · 75 阅读 · 0 评论 -
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 · 83 阅读 · 0 评论 -
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 · 69 阅读 · 0 评论 -
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 · 85 阅读 · 0 评论 -
leetcode回溯法总结
第二遍做leetcode 中的回溯法, 发现不光没有更好的理解,甚至遗忘了很多。 所以今天觉得做一篇有关回溯法的总结首先,回溯法的基本思想:从一条路往前走,能进则进,不能进则退回,换一条路再试回溯法的基本定义和概念首先要明确下面三个概念1约束函数:约束函数是根据题意定出, 通过描述合法解的一般特征用于去除不合法的解,从而避免继续搜索出这个不合法解的剩余部分2状态空间树状态空间树是一个对...原创 2020-04-02 04:14:49 · 154 阅读 · 0 评论 -
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 · 72 阅读 · 0 评论 -
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 · 67 阅读 · 0 评论 -
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 · 62 阅读 · 0 评论 -
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 · 125 阅读 · 0 评论 -
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 · 73 阅读 · 0 评论 -
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 · 158 阅读 · 0 评论 -
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 · 85 阅读 · 0 评论 -
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 · 70 阅读 · 0 评论 -
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 · 56 阅读 · 0 评论 -
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 · 73 阅读 · 0 评论 -
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 · 76 阅读 · 0 评论 -
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 · 83 阅读 · 0 评论 -
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 · 81 阅读 · 0 评论 -
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 · 63 阅读 · 0 评论 -
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 · 107 阅读 · 0 评论 -
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 · 56 阅读 · 0 评论 -
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 · 80 阅读 · 0 评论 -
leetcode#104. Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Note: A leaf is a node with no children....原创 2020-02-25 08:41:26 · 102 阅读 · 0 评论 -
leetnode#96. Unique Binary Search Trees
Given n, how many structurally unique BST’s (binary search trees) that store values 1 … n?Example:Input: 3Output: 5Explanation:Given n = 3, there are a total of 5 unique BST’s:1 3 3 ...原创 2020-02-25 05:48:57 · 63 阅读 · 0 评论 -
leetcode# Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes’ values.Example:Input: [1,null,2,3]12/3Output: [1,3,2]Follow up: Recursive solution is trivial, could you do it iteratively?题意很...原创 2020-02-23 06:39:40 · 62 阅读 · 0 评论 -
leetcode#90. Subsets II
Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.Example:Input: [1,2,2]Outp...原创 2020-02-21 06:32:48 · 70 阅读 · 0 评论 -
leetcode#86. Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of th...原创 2020-02-21 04:58:34 · 55 阅读 · 0 评论 -
leetcode#83. Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.Example 1:Input: 1->1->2Output: 1->2Example 2:Input: 1->1->2->3->3Output: 1->2-&...原创 2020-02-20 14:14:40 · 59 阅读 · 0 评论 -
leetcode# 82. Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.Example 1:Input: 1->2->3->3->4->4->5Output: 1->2-...原创 2020-02-20 13:48:53 · 105 阅读 · 0 评论 -
leetcode#80. Remove Duplicates from Sorted Array II
Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length.Do not allocate extra space for another array, you must do this by modi...原创 2020-02-20 04:07:27 · 55 阅读 · 0 评论 -
leetcode # 78 subset
Given a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.Example:Input: nums = [1,2,3]Output:[[3],[1],[2],...原创 2020-02-19 09:36:24 · 81 阅读 · 0 评论 -
leetcode #77 combination
Given two integers n and k, return all possible combinations of k numbers out of 1 … n.Example:Input: n = 4, k = 2Output:[[2,4],[3,4],[2,3],[1,2],[1,3],[1,4],]看到这种排列的题目 第一想到就是backtracking...原创 2020-02-19 07:35:19 · 138 阅读 · 0 评论 -
leetcode #75 Sort Colors
Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the int...原创 2020-02-19 07:04:30 · 104 阅读 · 1 评论 -
leetcode# 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 i...原创 2020-02-19 03:42:00 · 64 阅读 · 0 评论 -
leetcode 64. Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at an...原创 2020-02-17 03:31:38 · 55 阅读 · 0 评论 -
leetcode#62 unique paths
Unique PathsMedium2384174Add to ListShareA robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any po...原创 2020-02-16 06:27:41 · 66 阅读 · 0 评论 -
leetcode #61 rotate list
Given a linked list, rotate the list to the right by k places, where k is non-negative.Example 1:Input: 1->2->3->4->5->NULL, k = 2Output: 4->5->1->2->3->NULLExplanati...原创 2020-02-14 14:32:23 · 59 阅读 · 0 评论