
LeetCode 题解 C++版
LeetCode 题解
zhb1nk
字节跳动前端工程师
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode 539. 最小时间差
https://leetcode-cn.com/problems/minimum-time-difference/给定一个 24 小时制(小时:分钟)的时间列表,找出列表中任意两个时间的最小时间差并已分钟数表示。示例 1:输入: [“23:59”,“00:00”]输出: 1备注:列表中时间数在 2~20000 之间。每个时间取值在 00:00~23:59 之间。用stringst...原创 2019-04-01 21:26:58 · 404 阅读 · 0 评论 -
LeetCode 650. 2 Keys Keyboard
https://leetcode-cn.com/problems/2-keys-keyboard/submissions/最初在一个记事本上只有一个字符 ‘A’。你每次可以对这个记事本进行两种操作:Copy All (复制全部) : 你可以复制这个记事本中的所有字符(部分的复制是不允许的)。Paste (粘贴) : 你可以粘贴你上一次复制的字符。给定一个数字 n 。你需要使用最少的操作次数...原创 2019-03-21 16:16:30 · 233 阅读 · 0 评论 -
LeetCode 456. 132 Pattern
https://leetcode.com/problems/132-pattern/给定一个整数序列:a1, a2, …, an,一个132模式的子序列 ai, aj, ak 被定义为:当 i < j < k 时,ai < ak < aj。设计一个算法,当给定有 n 个数字的序列时,验证这个序列中是否含有132模式的子序列。注意:n 的值小于15000。示例1:输入...原创 2019-03-19 21:56:17 · 257 阅读 · 0 评论 -
LeetCode 916.Word Subsets
https://leetcode.com/problems/word-subsets/用map记录每个集合A中的单词,超时class Solution {public: vector<string> ans; unordered_map<char, int> map1; // 返回a是否包含b bool isContain(string...原创 2019-03-18 22:03:43 · 257 阅读 · 0 评论 -
LeetCode 766. Toeplitz Matrix
https://leetcode.com/problems/toeplitz-matrix/A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element.Now given an M x N matrix, return True if and only if the matr...原创 2019-02-02 14:07:52 · 216 阅读 · 0 评论 -
LeetCode 169 Majority Element
https://leetcode.com/problems/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 a...原创 2019-02-02 14:07:35 · 151 阅读 · 1 评论 -
LeetCode 575. Distribute Candies
题目链接:LeetCode 575Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of the corresponding kind. You need t...原创 2019-01-29 19:53:17 · 250 阅读 · 0 评论 -
LeetCode 463. Island Perimeter
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water.Grid cells are connected horizontally/vertically (not diagonally). The grid is completely ...原创 2019-01-28 14:19:07 · 231 阅读 · 0 评论 -
LeetCode 349. Intersection of Two Arrays
https://leetcode.com/problems/intersection-of-two-arrays/Given two arrays, write a function to compute their intersection.Example 1:Input: nums1 = [1,2,2,1], nums2 = [2,2]Output: [2]Example 2:I...原创 2019-01-28 11:25:26 · 177 阅读 · 0 评论 -
LeetCode 172. Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.Example 1:Input: 3Output: 0Explanation: 3! = 6, no trailing zero.Example 2:Input: 5Output: 1Explanation: 5! = 120, one trailing ...原创 2019-01-26 19:27:19 · 234 阅读 · 1 评论 -
LeetCode 219 Contains Duplicate II
Contains Duplicate II - LeetCodeGiven an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute differen...原创 2019-01-26 16:50:03 · 215 阅读 · 0 评论 -
LeetCode 849. Maximize Distance to Closest Person
LeetCode 849In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is empty.There is at least one empty seat, and at least one person sitting.Alex wants to si...原创 2019-01-24 20:07:42 · 229 阅读 · 0 评论 -
LeetCode 121. Best Time to Buy and Sell Stock
LeetCode 121Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of...原创 2019-01-23 18:42:17 · 267 阅读 · 0 评论 -
LeetCode 697. Degree of an Array
Degree of an Array - LeetCodeGiven a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.Your task is to find the s...原创 2019-01-22 20:12:55 · 237 阅读 · 0 评论 -
LeetCode 11. Container With Most Water
Container With Most Water - LeetCodeGiven 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 line i...原创 2019-01-21 20:19:53 · 181 阅读 · 0 评论 -
LeetCode 557. Reverse Words in a String III
题目链接Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Input: "Let's take LeetCode contest...原创 2019-01-20 21:07:20 · 217 阅读 · 0 评论 -
LeetCode 66. Plus One
LeetCode 66. Plus OneGiven a non-empty array of digits representing 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 l...原创 2019-01-20 20:02:11 · 146 阅读 · 0 评论 -
LeetCode 40. Combination Sum II
Combination Sum II - LeetCodeGiven a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target....原创 2019-01-20 16:27:40 · 142 阅读 · 0 评论 -
LeetCode 90. Subsets II
Subsets II - LeetCodeGiven 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.Exampl...原创 2019-01-20 15:55:03 · 187 阅读 · 0 评论 -
LeetCode 22. Generate Parenthese
Generate Parentheses - LeetCodeGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "((...原创 2019-01-20 14:25:57 · 240 阅读 · 0 评论 -
LeetCode 35. Search Insert Position
Given a sorted array 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.You may assume no duplicates in the array.Ex...原创 2019-01-18 16:26:56 · 136 阅读 · 0 评论 -
LeetCode 20. Valid Parentheses
Given a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of bra...原创 2019-01-18 16:16:36 · 200 阅读 · 0 评论 -
LeetCode 9. Palindrome Number
LeetCode 9. Palindrome NumberDetermine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.Example 1:Input: 121Output: trueExample 2:Input:...原创 2019-01-17 18:34:19 · 131 阅读 · 0 评论 -
LeetCode 78. Subsets
Subsets - LeetCodeGiven 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...原创 2019-01-14 22:19:28 · 342 阅读 · 0 评论 -
LeetCode 47. Permutation II
Permutations II - LeetCodeGiven a collection of numbers that might contain duplicates, return all possible unique permutations.Example:Input: [1,1,2]Output:[ [1,1,2], [1,2,1], [2,1,1]]S...原创 2019-01-14 18:25:06 · 255 阅读 · 0 评论 -
LeetCode 46. Permutaion
Permutations- LeetCodeGiven a collection of distinct integers, return all possible permutations.Example:Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]...原创 2019-01-14 18:24:47 · 238 阅读 · 0 评论 -
LeetCode 17. Letter Combinations of a Phone Number
Letter Combinations of a Phone Number - LeetCodeGiven a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to let...原创 2019-01-14 13:22:58 · 146 阅读 · 0 评论 -
LeetCode 684. Redundant Connection
In this problem, a tree is an undirected graph that is connected and has no cycles.The given input is a graph that started as a tree with N nodes (with distinct values 1, 2, …, N), with one additiona...原创 2019-01-13 17:08:22 · 223 阅读 · 0 评论 -
LeetCode 520. Delete Capital
Given a word, you need to judge whether the usage of capitals in it is right or not.We define the usage of capitals in a word to be right when one of the following cases holds:All letters in this w...原创 2019-01-13 10:59:35 · 161 阅读 · 0 评论 -
LeetCode 696. Count Binary Substrings
Count Binary Substrings - LeetCodeGive a string s, count the number of non-empty (contiguous) substrings that have the same number of 0’s and 1’s, and all the 0’s and all the 1’s in these substrings ...原创 2019-01-12 23:54:40 · 139 阅读 · 0 评论 -
LeetCode 606. Construct string from Binary Tree
Construct String from Binary Tree - LeetCodeYou need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way.The null node needs to be represen...原创 2019-01-12 23:13:20 · 243 阅读 · 0 评论 -
LeetCode 542. 01Matrix
Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.The distance between two adjacent cells is 1.Example 1:Input:0 0 00 1 00 0 0Output:0 0 00 1 00 0 0Exam...原创 2019-01-12 22:57:28 · 236 阅读 · 0 评论 -
LeetCode 690. Employee Importance
You are given a data structure of employee information, which includes the employee’s unique id, his importance value and his direct subordinates’ id.For example, employee 1 is the leader of employee...原创 2019-01-12 20:04:07 · 133 阅读 · 0 评论 -
LeetCode 213. House Robber II
House Robber II - LeetCodeYou 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. Tha...原创 2019-01-12 16:56:48 · 197 阅读 · 0 评论 -
LeetCode 198. House Robber
House Robber - LeetCodeYou 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 the...原创 2019-01-12 15:45:29 · 237 阅读 · 0 评论 -
LeetCode 494. Target Sum
You are given a list of non-negative integers, a1, a2, …, an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol.Find out how many...原创 2019-01-11 21:41:59 · 190 阅读 · 0 评论 -
LeetCode 491. Increasing Subsequences
Given an integer array, your task is to find all the different possible increasing subsequences of the given array, and the length of an increasing subsequence should be at least 2 .Example:Input: [...原创 2019-01-11 20:09:31 · 224 阅读 · 0 评论 -
LeetCode 113. Path Sum II
Path Sum II - LeetCodeGiven 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 t...原创 2019-01-11 14:51:25 · 146 阅读 · 1 评论 -
LeetCode 101. Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But ...原创 2019-01-11 12:21:12 · 235 阅读 · 0 评论 -
LeetCode 100. Same Tree
Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.Example 1:...原创 2019-01-11 12:07:28 · 143 阅读 · 0 评论