- 博客(34)
- 资源 (4)
- 收藏
- 关注
原创 剑指 Offer 09. 用两个栈实现队列(Leetcode每日一题-2020.06.30)
Problem用两个栈实现一个队列。队列的声明如下,请实现它的两个函数 appendTail 和 deleteHead ,分别完成在队列尾部插入整数和在队列头部删除整数的功能。(若队列中没有元素,deleteHead 操作返回 -1 )Example1输入:[“CQueue”,“appendTail”,“deleteHead”,“deleteHead”][[],[3],[],[]]输出:[null,null,3,-1]Example2输入:[“CQueue”,“deleteHead”
2020-06-30 14:01:41 265
原创 215. Kth Largest Element in an Array(Leetcode每日一题-2020.06.29)
ProblemFind the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.Example1Input: [3,2,1,5,6,4] and k = 2Output: 5Example2Input: [3,2,3,1,2,4,5,5,6] and k = 4Output:
2020-06-29 20:08:45 186
原创 归并排序模板
#include <iostream>using namespace std;const int N = 1e6 + 10;int q[N];int n;void quick_sort(int q[],int l,int r){ if(l >= r) return; int i = l-1; int j = r + 1; int x = q[l+r>>1]; while(i < j) {
2020-06-28 15:43:40 231
原创 快速排序模板
#include <iostream>using namespace std;const int N = 1e6 + 10;int q[N];int n;void quick_sort(int q[],int l,int r){ if(l >= r) return; int i = l-1; int j = r + 1; int x = q[l+r>>1]; while(i < j) {
2020-06-28 15:28:24 238
原创 209. Minimum Size Subarray Sum(Leetcode每日一题-2020.06.28)
ProblemGiven an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn’t one, return 0 instead.ExampleInput: s = 7, nums = [2,3,1,2,4,3]Output: 2Explanation: the suba
2020-06-28 11:14:05 210
原创 41. First Missing Positive(Leetcode每日一题-2020.06.27)
ProblemGiven an unsorted integer array, find the smallest missing positive integer.Note:Your algorithm should run in O(n) time and uses constant extra space.Example1Input: [1,2,0]Output: 3Example2Input: [3,4,-1,1]Output: 2Example3Input: [7,
2020-06-27 10:50:49 469
原创 AcWing 3.完全背包问题
问题描述问题解析朴素做法#include <iostream>using namespace std;const int N = 1010;int n;int m;int v[N];int w[N];int f[N][N];int main(){ cin >> n >> m; for(int i = 1;i<=n;++i) cin >> v[i] >> w[i];
2020-06-26 16:31:15 224
原创 AcWing 2.01背包问题
问题描述问题解析朴素做法#include <iostream>#include <algorithm>using namespace std;const int N = 1010;int n;int m;int v[N];int w[N];int f[N][N];int main(void){ cin >> n >> m; for(int i = 1;i<=n;++i) {
2020-06-26 15:41:51 236
原创 面试题 02.01. Remove Duplicate Node LCCI(Leetcode每日一题-2020.06.26)
ProblemWrite code to remove duplicates from an unsorted linked list.Note:The length of the list is within the range[0, 20000].The values of the list elements are within the range [0, 20000].Example1Input: [1, 2, 3, 3, 2, 1]Output: [1, 2, 3]Exam
2020-06-26 10:38:07 297
原创 139. Word Break(Leetcode每日一题-2020.06.25)
ProblemGiven a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.Note:The same word in the dictionary may be reused multipl
2020-06-25 22:20:34 218
原创 16. 3Sum Closest(Leetcode每日一题-2020.06.24)
ProblemGiven an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution.Constraints:3 <=
2020-06-24 20:46:19 223
原创 67. Add Binary(Leetcode每日一题-2020.06.23)
ProblemGiven two binary strings, return their sum (also a binary string).The input strings are both non-empty and contains only characters 1 or 0.Constraints:Each string consists only of ‘0’ or ‘1’ characters.1 <= a.length, b.length <= 10^4Eac
2020-06-23 21:43:05 267
原创 面试题 16.18. Pattern Matching LCCI(Leetcode每日一题-2020.06.22)
ProblemYou are given two strings, pattern and value. The pattern string consists of just the letters a and b, describing a pattern within a string. For example, the string catcatgocatgo matches the pattern aabab (where cat is a and go is b). It also match
2020-06-22 22:39:03 266
原创 124. Binary Tree Maximum Path Sum(Leetcode每日一题-2020.06.21)
ProblemGiven a non-empty binary 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 connections. The path must contain at least one node and d
2020-06-21 13:26:07 186
原创 10. Regular Expression Matching(Leetcode每日一题-2020.06.20)
ProblemGiven an input string (s) and a pattern §, implement regular expression matching with support for ‘.’ and ‘*’.‘.’ Matches any single character.‘*’ Matches zero or more of the preceding element.The matching should cover the entire input string
2020-06-20 12:05:52 263
原创 125. Valid Palindrome(Leetcode每日一题-2020.06.19)
ProblemGiven a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Note: For the purpose of this problem, we define empty string as valid palindrome.Example1Input: “A man, a plan, a canal: Panama”Outpu
2020-06-19 21:54:52 173
原创 1028. Recover a Tree From Preorder Traversal(Leetcode每日一题-2020.06.18)
ProblemWe run a preorder depth first search on the root of a binary tree.At each node in this traversal, we output D dashes (where D is the depth of this node), then we output the value of this node. (If the depth of a node is D, the depth of its immedi
2020-06-18 22:40:32 240
原创 1014. Best Sightseeing Pair(Leetcode每日一题-2020.06.17)
ProblemGiven an array A of positive integers, A[i] represents the value of the i-th sightseeing spot, and two sightseeing spots i and j have distance j - i between them.The score of a pair (i < j) of sightseeing spots is (A[i] + A[j] + i - j) : the su
2020-06-17 21:36:58 222
原创 297. Serialize and Deserialize Binary Tree(Leetcode每日一题-2020.06.16)
ProblemSerialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another comp
2020-06-16 21:15:19 225
原创 14. Longest Common Prefix(Leetcode每日一题-2020.06.15)
ProblemWrite a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string “”.All given inputs are in lowercase letters a-z.Example1Input: [“flower”,“flow”,“flight”]Output: “fl”
2020-06-15 19:26:26 193
原创 1300. Sum of Mutated Array Closest to Target(Leetcode每日一题-2020.06.14)
ProblemGiven an integer array arr and a target value target, return the integer value such that when we change all the integers larger than value in the given array to be equal to value, the sum of the array gets as close as possible (in absolute differen
2020-06-15 19:23:43 258
原创 70. Climbing Stairs(Leetcode每日一题-2020.06.13)
ProblemYou 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 integer.Example1Input: 2Output: 2Explanation
2020-06-15 19:20:38 232
原创 15. 3Sum(Leetcode每日一题-2020.06.12)
ProblemGiven an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.ExampleGiven array nums = [-1, 0, 1, 2, -1, -4],A solution set is:[[-1, 0, 1],[-
2020-06-13 08:13:33 209
原创 739. Daily Temperatures(Leetcode每日一题-2020.06.11)
ProblemGiven a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead.For example, g
2020-06-13 08:08:57 232
原创 9. Palindrome Number(Leetcode每日一题-2020.06.10)
ProblemDetermine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.Example1Input: 121Output: trueExample2Input: -121Output: falseExplanation: From left to right, it reads -121. From right t
2020-06-10 20:32:18 219
原创 面试题46. 把数字翻译成字符串(Leetcode每日一题-2020.06.09)
Problem给定一个数字,我们按照如下规则把它翻译为字符串:0 翻译成 “a” ,1 翻译成 “b”,……,11 翻译成 “l”,……,25 翻译成 “z”。一个数字可能有多个翻译。请编程实现一个函数,用来计算一个数字有多少种不同的翻译方法。Example输入: 12258输出: 5解释: 12258有5种不同的翻译,分别是"bccfi", “bwfi”, “bczi”, “mcfi"和"mzi”Solution动态规划,本题与91. Decode Ways类似。class Sol
2020-06-09 22:27:52 381
原创 990. Satisfiability of Equality Equations(Leetcode每日一题-2020.06.08)
ProblemGiven an array equations of strings that represent relationships between variables, each string equations[i] has length 4 and takes one of two different forms: “a==b” or “a!=b”. Here, a and b are lowercase letters (not necessarily different) that
2020-06-08 20:51:28 198
原创 126. Word Ladder II(Leetcode每日一题-2020.06.07)
ProblemGiven two words (beginWord and endWord), and a dictionary’s word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:Only one letter can be changed at a timeEach transformed word must exist in the word list. N
2020-06-07 22:27:35 250
原创 128. Longest Consecutive Sequence(Leetcode每日一题-2020.06.06)
ProblemGiven an unsorted array of integers, find the length of the longest consecutive elements sequence.Your algorithm should run in O(n) complexity.ExampleInput: [100, 4, 200, 1, 3, 2]Output: 4Explanation: The longest consecutive elements sequence
2020-06-07 15:15:18 176
原创 54. Spiral Matrix&面试题29. 顺时针打印矩阵(Leetcode每日一题-2020.06.05)
ProblemGiven a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.Example1Input:[[ 1, 2, 3 ],[ 4, 5, 6 ],[ 7, 8, 9 ]]Output: [1,2,3,6,9,8,7,4,5]Example2Input:[[1, 2, 3, 4],[5, 6, 7, 8],[9,10,11
2020-06-07 15:09:12 368
原创 837. New 21 Game(Leetcode每日一题-2020.06.03)
ProblemAlice plays the following game, loosely based on the card game “21”.Alice starts with 0 points, and draws numbers while she has less than K points. During each draw, she gains an integer number of points randomly from the range [1, W], where W is
2020-06-04 22:25:14 254
原创 238. Product of Array Except Self&剑指 Offer 66. 构建乘积数组(Leetcode每日一题-2020.06.04)
ProblemGiven 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].ExampleInput: [1,2,3,4]Output: [24,12,8,6]ConstraintsIt’s guaranteed that the p
2020-06-04 22:22:01 182
原创 面试题64. 求1+2+…+n(Leetcode每日一题-2020.06.02)
Problem求 1+2+…+n ,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。Example1输入: n = 3输出: 6Example2输入: n = 9输出: 45Constraints1 <= n <= 10000Solution逻辑短路+递归class Solution {public: int sumNums(int n) { n >= 1 &a
2020-06-02 18:36:37 184
原创 1431. Kids With the Greatest Number of Candies(Leetcode每日一题-2020.06.01)
ProblemGiven the array candies and the integer extraCandies, where candies[i] represents the number of candies that the ith kid has.For each kid check if there is a way to distribute extraCandies among the kids such that he or she can have the greatest n
2020-06-01 20:36:33 409
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人