leetcode刷题c++/python
计划刷leetcode算法题300道,使用c++/python
别说话写代码
这个作者很懒,什么都没留下…
展开
-
leetcode-279. Perfect Squares 完全平方数
Given a positive integern, find the least number of perfect square numbers (for example,1, 4, 9, 16, ...) which sum ton. Example 1: Input: n = 12Output: 3 Explanation: 12 = 4 + 4 + 4...原创 2019-06-27 10:11:50 · 392 阅读 · 0 评论 -
leetcode-300. Longest Increasing Subsequence 最长上升子序列
Given an unsorted array of integers, find the length of longest increasing subsequence. Example: Input: [10,9,2,5,3,7,101,18]Output: 4 Explanation: The longest increasing subsequence is...原创 2019-06-27 10:03:23 · 261 阅读 · 0 评论 -
leetcode-221. Maximal Square 最大正方形
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area. Example: Input: 1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0Output: 4 ...原创 2019-06-08 16:33:24 · 346 阅读 · 0 评论 -
leetcode-85. Maximal Rectangle 最大矩形
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. Example: Input:[ ["1","0","1","0","0"], ["1","0","1","1","1"], ...原创 2019-06-07 17:17:01 · 295 阅读 · 0 评论 -
leetcode-84. Largest Rectangle in Histogram 柱状图中最大的矩形
Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. Above is a histogram wher...原创 2019-06-07 17:13:01 · 371 阅读 · 0 评论 -
leetcode-240. Search a 2D Matrix II 搜索二维矩阵 II
Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties: Integers in each row are sorted in ascending from left to right. Intege...原创 2019-05-28 22:04:17 · 213 阅读 · 0 评论 -
leetcode-207. Course Schedule
There are a total ofncourses you have to take, labeled from0ton-1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as...原创 2019-04-15 23:20:02 · 310 阅读 · 0 评论 -
leetcode-209. Minimum Size Subarray Sum 长度最小的子数组
Given an array ofnpositive integers and a positive integers, find the minimal length of acontiguoussubarray of which the sum ≥s. If there isn't one, return 0 instead. Example: Inpu...原创 2019-04-10 22:51:01 · 135 阅读 · 0 评论 -
leetcode-208. Implement Trie (Prefix Tree) 实现 Trie (前缀树)
Implement a trie withinsert,search, andstartsWithmethods. Example: Trie trie = new Trie();trie.insert("apple");trie.search("apple"); // returns truetrie.search("app"); // re...原创 2019-04-09 23:06:30 · 343 阅读 · 0 评论 -
leetcode-76. Minimum Window Substring 最小覆盖子串
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). Example: Input: S = "ADOBECODEBANC", T = "ABC"Output: "BANC"...原创 2019-03-21 22:26:10 · 260 阅读 · 0 评论 -
leetcode-647. Palindromic Substrings 回文子串
Given a string, your task is to count how many palindromic substrings in this string. The substrings with different start indexes or end indexes are counted as different substrings even they c...原创 2019-03-21 21:30:07 · 148 阅读 · 0 评论 -
leetcode-139. Word Break 单词拆分
Given anon-emptystringsand a dictionarywordDictcontaining a list ofnon-emptywords, determine ifscan be segmented into a space-separated sequence of one or more dictionary words. Note...原创 2019-03-18 15:15:45 · 231 阅读 · 0 评论 -
leetcode-72. Edit Distance 编辑距离
Given two wordsword1andword2, find the minimum number of operations required to convertword1toword2. You have the following 3 operations permitted on a word: Insert a character D...原创 2019-03-18 14:17:45 · 195 阅读 · 0 评论 -
leetcode-78. Subsets 子集
Given a set ofdistinctintegers,nums, return all possible subsets (the power set). Note:The solution set must not contain duplicate subsets. Example: Input: nums = [1,2,3]Output:...原创 2019-03-17 15:47:25 · 220 阅读 · 0 评论 -
leetcode-200. Number of Islands 岛屿的个数
Given a 2d grid map of'1's (land) and'0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may as...原创 2019-03-15 22:19:29 · 305 阅读 · 0 评论 -
leetcode-222. Count Complete Tree Nodes 完全二叉树的节点个数
Given acompletebinary tree, count the number of nodes. Note: Definition of a complete binary tree fromWikipedia: In a complete binary tree every level, except possibly the last, is c...原创 2019-03-15 15:43:51 · 179 阅读 · 0 评论 -
leetcode-124. Binary Tree Maximum Path Sum 二叉树中的最大路径和
Given anon-emptybinary tree, find the maximum path sum. For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child co...原创 2019-03-14 14:55:26 · 301 阅读 · 0 评论 -
leetcode-77. Combinations 组合
Given two integersnandk, return all possible combinations ofknumbers out of 1 ...n. Example: Input:n = 4, k = 2Output:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],] ...原创 2019-03-11 22:42:24 · 317 阅读 · 0 评论 -
leetcode-326. Power of Three 3的幂
Given an integer, write a function to determine if it is a power of three. Example 1: Input: 27Output: true Example 2: Input: 0Output: false Example 3: Input: 9Outpu...原创 2019-03-11 21:58:33 · 187 阅读 · 0 评论 -
leetcode-231. Power of Two 2的幂
Given an integer, write a function to determine if it is a power of two. Example 1: Input: 1Output: true Explanation: 20= 1 Example 2: Input: 16Output: trueExplanation: 24...原创 2019-03-11 21:27:51 · 181 阅读 · 0 评论 -
347. Top K Frequent Elements 前K个高频元素
Given a non-empty array of integers, return the k most frequent elements. Example 1: Input: nums = [1,1,1,2,2,3], k = 2Output: [1,2] Example 2: Input: nums = [1], k = 1Output:...原创 2019-02-25 20:26:12 · 191 阅读 · 0 评论 -
239. Sliding Window Maximum 滑动窗口最大值
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding wind...原创 2019-02-25 19:54:08 · 189 阅读 · 0 评论 -
287. Find the Duplicate Number 寻找重复数
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number...原创 2019-02-24 21:14:55 · 157 阅读 · 0 评论 -
283. Move Zeroes 移动零
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. Example: Input: [0,1,0,3,12]Output: [1,3,12,0,0] ...原创 2019-02-24 20:49:47 · 154 阅读 · 0 评论 -
169. Majority Element 求众数
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋times. You may assume that the array is non-empty and the majority elemen...原创 2019-02-24 20:29:19 · 154 阅读 · 0 评论 -
238. Product of Array Except Self 除自身以外数组的乘积
Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Example: Input: [1,2,3,4...原创 2019-02-24 20:20:57 · 123 阅读 · 0 评论 -
155. Min Stack 最小栈
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. ...原创 2019-02-24 20:10:55 · 176 阅读 · 0 评论 -
152. Maximum Product Subarray 乘积最大子序列
Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product. Example 1: Input: [2,3,-2,4]Output: 6Explanatio...原创 2019-02-24 20:03:02 · 169 阅读 · 0 评论 -
137. Single Number II 只出现一次的数字 II
Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note: Your algorithm should have a linear runtim...原创 2019-02-22 23:19:58 · 138 阅读 · 0 评论 -
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 ...原创 2019-02-22 22:47:17 · 142 阅读 · 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 verti...原创 2019-02-22 22:40:43 · 220 阅读 · 0 评论 -
leetcode-4. Median of Two Sorted Arrays 寻找两个有序数组的中位数
There are two sorted arraysnums1andnums2of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). You may assumen...原创 2019-02-21 23:15:27 · 134 阅读 · 0 评论 -
324. Wiggle Sort II 摆动排序 II
Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3].... Example 1: Input: nums = [1, 5, 1, 1, 6, 4]Output: One possible answer is [1, 4, 1, ...原创 2019-02-21 17:57:20 · 228 阅读 · 0 评论 -
lintcode-508. Wiggle Sort
Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= nums[2] <= nums[3].... Example Example 1: Input: [3, 5, 2, 1, 6, 4]Output: [1, 6...原创 2019-02-21 17:44:15 · 136 阅读 · 0 评论 -
leetcode-146. LRU Cache LRU缓存机制
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put. get(key) - Get the value (will always be positive) of the ke...原创 2019-02-20 23:13:00 · 195 阅读 · 0 评论 -
leetcode-215. Kth Largest Element in an Array 数组中的第K个最大元素
Find thekth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Example 1: Input: [3,2,1,5,6,4] and k = 2Out...原创 2019-02-20 21:42:30 · 159 阅读 · 0 评论 -
leetcode-70. Climbing Stairs 爬楼梯
You 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 ...原创 2019-01-28 22:00:29 · 210 阅读 · 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...原创 2019-01-28 21:58:12 · 263 阅读 · 0 评论 -
leetcode-213. House Robber II 打家劫舍 II
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house...原创 2019-01-27 14:18:53 · 188 阅读 · 0 评论 -
198. House Robber 打家劫舍
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent h...原创 2019-01-27 13:41:01 · 247 阅读 · 0 评论