![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
team79
我在努力。
展开
-
LeetCode 282. Expression Add Operators
题目Given a string that contains only digits 0-9 and a target value, return all possibilities to add binary operators (not unary) +, -, or * between the digits so they evaluate to the target value.Exampl原创 2017-02-07 18:42:24 · 295 阅读 · 0 评论 -
LeetCode 786. K-th Smallest Prime Fraction
题意有一个由1和质数组成的序列,对于序列中的任意p,q,若p题解数列长度是3000,所以最多也就10^6个分数,快排一下复杂度应该够的。但是这题应该是卡常数了。快排复杂度是N2logN2N2logN2N^2logN^2,N是数列长度,也就是2∗N2logN2∗N2logN2*N^2logN。 对于数列[1,2,3,5],我们考虑:1/21/3 2/31/5 2/5 3/5...原创 2018-02-27 15:17:14 · 451 阅读 · 0 评论 -
LeetCode 10. Regular Expression Matching
题意给定两个字符串,用后面的串去匹配前面的串,问能不能匹配成功。 第二个串中‘.’可以表示任意字符,‘*’表示前一个字符可以出现任意次(包括0次)题解用记忆化搜索来做,dp[i][j]表示s的后i个字符能不能和p的后j个字符匹配。 然后分情况搜索来就行了。代码int dp[2000][2000];class Solution {public: bo...原创 2018-02-28 11:04:02 · 195 阅读 · 0 评论 -
LeetCode 335. Self Crossing
题意给定一个步长数组,分别按北西南东方向走,问会不会穿过之前走过的地方,需要空间复杂度o(1)的解法。题解题目需要空间复杂度o(1)的解法,所以肯定每一步只与之前的几步有关系,然后可以画图分析一下超过六步之后之前的就肯定不会遇到了。所以只需要向前考虑六步就行了。代码class Solution {public: bool isSelfCrossing(ve...原创 2018-02-23 20:07:48 · 178 阅读 · 0 评论 -
LeetCode 45. Jump Game II
题意在位置i时,能向前走0~nums[i]步,问最少多少次能走到最右。题解maxpos表示step次能走到的最远位置,然后pos为当前位置,用pos~maxpos之间的值更新maxpos,然后step++。代码class Solution {public: int jump(vector<int>& nums) { int ...原创 2018-02-24 21:00:26 · 138 阅读 · 0 评论 -
LeeCode 675. Cut Off Trees for Golf Event
题意给你一个二维矩阵表示森林,为0的地方不可行,大于1的地方表示树,值的大小就是树的高度,所有大于等于1的地方是可以走的,现在你从(0,0)(0,0)(0,0)开始,按树的高度从小到大遍历所有的树,问最短路径。题解存下所有树的坐标,按树的高度从小大大依次用bfs求最短路径就好了。代码struct Node { int x, y, step; int h;...原创 2018-03-21 21:33:02 · 300 阅读 · 0 评论 -
LeeCode 664. Strange Printer
题意有一个特殊的printer,每次可以从任意位置输出任意长度相同字符,但是会覆盖之前的输出,现在给一个字符串,问需要最少多少次能输出这个字符串。题解对于一个字符串:直接分成前后两部分输出如果首尾字符相同,那么可以先输出整个字符串长度的首字符。然后再输出中间的字符。那么另dp[i][j]dp[i][j]dp[i][j]表示输出i到j这一部分的字符串需要的最少次数,那么:...原创 2018-04-02 10:56:42 · 230 阅读 · 0 评论 -
LeeCode 828. Unique Letter String
题意一个字符串SSS的UNIQ(S)UNIQ(S)UNIQ(S)值为其中只出现一次的字符的数量。 现给定字符串SSS,求所有的UNIQ(sub(S))UNIQ(sub(S))UNIQ(sub(S))的和,其中sub(S)sub(S)sub(S)为SSS的连续子串。题解这题SSS的长度是10000,直接暴力是肯定不行的。 那么我们一个个的考虑,先考虑字符AAA。假设是: ...原创 2018-07-25 10:58:31 · 683 阅读 · 0 评论 -
LeeCode 587. Erect the Fence
求凸包。 但是这题有个问题就是需要把在边界上的点也求出来,那么在判断cross的时候应该是<0 而不是 <=0。 还有一个问题是,排序的时候当极角相同的时候,按x从小到大的顺序排列的,那么最后几个共线的点顺序应该倒过来,不然结果只包含一个点。#include <iostream>#include <vector>#include <algori...原创 2018-07-30 17:24:01 · 299 阅读 · 0 评论 -
LeetCode 741. Cherry Pickup
题意一个迷宫,从左上走到右下,走两次,最多能收集多少个1题解dp[i][j][k][l]" role="presentation" style="position: relative;">dp[i][j][k][l]dp[i][j][k][l]dp[i][j][k][l] 表示两次分别走到(i,j)" role="presentation" style="position: relat原创 2018-01-25 13:28:05 · 725 阅读 · 0 评论 -
LeetCode 493. Reverse Pairs
题目求数组中满足 i 2*nums[j]的对数。题解先把所有的数及其两倍的树重排序一下,然后再用树状数组来统计。int sum[100010];int N = 100010;class Solution {public: inline int lowbit(int x) { return x & (-x); } void原创 2018-01-23 10:31:18 · 441 阅读 · 0 评论 -
LeetCode 164. Maximum Gap
题目Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements.You ma原创 2017-02-05 12:45:44 · 244 阅读 · 0 评论 -
LeetCode 99. Recover Binary Search Tree
题目Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note: A solution using O(n) space is pretty straight forward. Could you devise a con原创 2017-02-05 11:52:14 · 374 阅读 · 0 评论 -
LeetCode 327. Count of Range Sum
题目Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive. Range sum S(i, j) is defined as the sum of the elements in nums between indices i and j (i ≤ j), in原创 2017-02-05 11:20:46 · 454 阅读 · 0 评论 -
LeetCode 25. Reverse Nodes in k-Group
给一个链表,每k个反转一下,最后不够的不反转。 写了半天,实在是太弱了。 struct XNode{ ListNode *t1, *t2; int flag; };class Solution {public: XNode dfs( ListNode* pre, ListNode* nows, int cnt, int k ){ //if( nows =原创 2017-02-04 14:32:04 · 269 阅读 · 0 评论 -
Leetcode 330. Patching Array
解法真的厉害!学习了!这道题给我们一个有序的正数数组nums,又给了我们一个正整数n,问我们最少需要给nums加几个数字,使其能组成[1,n]之间的所有数字,注意数组中的元素不能重复使用。我们定义一个变量miss,用来表示[0,n]之间最小的不能表示的值,那么初始化为1。那么此时我们能表示的范围是[0, miss),表示此时我们能表示0到miss-1的数,如果此时的num <= miss,那么我们可原创 2017-02-03 21:53:16 · 509 阅读 · 0 评论 -
LeetCode 316. Remove Duplicate Letters
题目Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order原创 2017-02-07 19:26:19 · 290 阅读 · 0 评论 -
LeetCode 214. Shortest Palindrome
题目Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.For example原创 2017-09-24 16:32:44 · 375 阅读 · 0 评论 -
LeetCode 639. Decode Ways II
题意A message containing letters from A-Z is being encoded to numbers using the following mapping way:'A' -> 1'B' -> 2...'Z' -> 26Beyond that, now the encoded string can also contain the character ‘*原创 2017-09-24 17:07:12 · 376 阅读 · 0 评论 -
LeeCode 798. Smallest Rotation with Highest Score
题意Example 1: Input: [2, 3, 1, 4, 0] Output: 3 Explanation: Scores for each K are listed below: K = 0, A = [2,3,1,4,0], score 2 K = 1, A = [3,1,4,0,2], score 3 K = 2, A = [1,4,0,2,3]...原创 2018-07-30 20:55:11 · 306 阅读 · 0 评论