- 博客(208)
- 资源 (1)
- 收藏
- 关注
原创 leetcode 76. 最小覆盖子串
自从上班后就没怎么刷过题了,以后考虑更新点技术文章。 给你一个字符串 S、一个字符串 T,请在字符串 S 里面找出:包含 T 所有字母的最小子串。 示例: 输入: S = "ADOBECODEBANC", T = "ABC" 输出: "BANC" 说明: 如果 S 中不存这样的子串,则返回空字符串 ""。 如果 S 中存在这样的子串,我们保证它是唯一的答案。 来源:力扣(LeetCode...
2020-04-06 21:04:26
449
3
原创 无题的题目
题目: 给定正整数N和D,生成所有行和、列和等于D的NxN的非负整数矩阵。给出 N <= 5, D <= 8 的每一个<N, D>下这样的矩阵的数目 当N = 2, D = 1时,有 1 0 0 1 两种情况 0 1 1 0 ...
2018-09-16 14:19:55
588
1
原创 cf F1. Stock Trading (dp)
F1. Stock Tradingtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem consists of three subproblems: for solving subproblem F1 you will re...
2018-04-21 23:20:15
620
原创 hihocoder #1032 : 最长回文子串 马拉车算法
#1032 : 最长回文子串时间限制:1000ms单点时限:1000ms内存限制:256MB描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编程的学习道路上一同前进。 这一天,他们遇到了一连串的字符串,于是小Hi就向小Ho提出了那个经典的问题:“小Ho,你能不能分别在这些字符串中找到它们每一个的最长回文子串呢?” 小Ho奇怪的问道:...
2018-04-20 21:47:01
387
原创 leetcode 98. 验证二叉搜索树
给定一个二叉树,判断其是否是一个有效的二叉搜索树。一个二叉搜索树有如下定义:左子树只包含小于当前节点的数。右子树只包含大于当前节点的数。所有子树自身必须也是二叉搜索树。示例 1: 2 / \ 1 3 二叉树[2,1,3], 返回 true.示例 2: 1 / \ 2 3 二叉树 [1,2,3], 返回 false.啊我有点蠢了。。中序遍历做/** * De...
2018-03-10 22:08:54
1585
原创 leetcode 69. x 的平方根
实现 int sqrt(int x) 函数。计算并返回 x 的平方根。x 保证是一个非负整数。 案例 1:输入: 4 输出: 2 案例 2:输入: 8 输出: 2 说明: 8 的平方根是 2.82842..., 由于我们想返回一个整数,小数部分将被舍去。 二分经典题目。class Solution { public: int mySqrt(int x) { long long le...
2018-03-07 11:06:01
513
原创 leetcode 66. 加一
给定一个非负整数组成的非空数组,给整数加一。可以假设整数不包含任何前导零,除了数字0本身。最高位数字存放在列表的首位。emmmclass Solution { public: vector<int> plusOne(vector<int>& digits) { int len = digits.size(); dfs(digi...
2018-03-04 22:19:02
745
原创 leetcode 63. 不同路径 II dp
这是“不同路径” 的进阶问题:现在考虑网格中有障碍物。那样将会有多少条不同的路径从左上角到右下角?网格中的障碍物和空位置分别用 1 和 0 来表示。例如,如下所示在 3x3 的网格中有一个障碍物。[ [0,0,0], [0,1,0], [0,0,0] ] 一共有 2 条不同的路径从左上角到右下角。注意: m 和 n 的值均不超过 100。i == 1 && j == 1...
2018-03-04 13:29:07
1329
原创 leetcode 56. 合并区间(贪心)
给出一个区间的集合, 请合并所有重叠的区间。示例:给出 [1,3],[2,6],[8,10],[15,18],返回 [1,6],[8,10],[15,18].贪心,先以start大小排序,这样保证start的是有序的。然后扩张end。代码也很容易理解,复杂度是nlogn/** * Definition for an interval. * struct Interval { * in...
2018-03-01 11:20:47
1713
原创 leetcode。57. 插入区间
给出一个无重叠的按照区间起始端点排序的区间列表。在列表中插入一个新的区间,你要确保列表中的区间仍然有序且不重叠(如果有必要的话,可以合并区间)。示例 1:给定区间 [1,3],[6,9],插入并合并 [2,5] 得到 [1,5],[6,9].示例 2:给定区间 [1,2],[3,5],[6,7],[8,10],[12,16],插入并合并 [4,9] 得到 [1,2],[3,10],[12,16]....
2018-03-01 11:18:29
568
原创 leetcode 49. 字谜分组
给定一个字符串数组,将相同字谜组合在一起。(字谜是指颠倒字母顺序而成的字)例如,给定 ["eat", "tea", "tan", "ate", "nat", "bat"],返回:[ ["ate", "eat","tea"], ["nat","tan"], ["bat&q
2018-02-22 15:34:38
2245
原创 leetcode。 48. 旋转图像
给定一个 n × n 的二维矩阵表示一个图像。将图像旋转 90 度(顺时针)。注意:你必须在原矩阵中旋转图像,请不要使用另一个矩阵来旋转图像。例 1:给出的输入矩阵 = [ [1,2,3], [4,5,6], [7,8,9] ], 旋转输入矩阵,使其变为 : [ [7,4,1], [8,5,2], [9,6,3] ] 例 2:给出的输入矩阵 = [ [ 5, 1,...
2018-02-22 15:14:51
1470
原创 leetcode。45. 跳跃游戏 II
给定一个非负整数数组,你最初位于数组的首位。数组中的每个元素表示你在该位置的最大跳跃长度。你的目标是用最小跳跃次数到达最后一个索引。例如: 给定一个数组 A = [2,3,1,1,4]跳到最后一个索引的最小跳跃数是 2。(从索引 0 跳到 1 跳1步,然后跳3步到最后一个索引。)注意:假设你总是可以到达最后一个索引位置。一开始以为是dp。。。其实是贪心,每次找范围内index + next最大的索...
2018-02-21 20:58:13
2866
原创 leetcode。 44. 通配符匹配
实现一个支持 '?' 和 '*' 的通配符匹配。'?' 匹配任何单个字符。 '*' 匹配任何数量的字符 (包括0个)。 匹配应覆盖 整个 输入字符串(而不是部分)。 这个函数原型为: bool isMatch(const char *s, const char *p) 示例: isMatch("aa","a") → false isMatch("aa","aa") → true isMatc...
2018-02-21 20:56:19
510
原创 leetcode 43. 字符串相乘
给定两个以字符串表示的非负整数 num1 和 num2,返回 num1 和 num2 的乘积。注意:num1 和 num2 的长度均小于110。num1 和 num2 均只包含数字 0-9。num1 和 num2 均不以零开头。你不能使用任何内置的大整数库或直接将输入转换为整数。string BigNumMultiply(string str1,string str2) { if (str...
2018-02-20 23:05:23
2455
原创 leetcode 42. 接雨水
给 n 个非负整数表示每个宽度为一的柱子的高度图,计算下雨之后能接多少水。例如,输入 [0,1,0,2,1,0,1,3,2,1,2,1],返回 6。上面的高度图由数组 [0,1,0,2,1,0,1,3,2,1,2,1] 表示,在这种情况下,可以接 6 个单位的雨水(蓝色部分)。 感谢 Marcos 贡献此图。木桶原理,盛的水取决于最短板。。。我们设置两个指针从左右两端开始向中间靠拢。。。我们根据短...
2018-02-20 18:28:53
4132
原创 leetcode 40. Combination Sum II
39的加强版。。。直接用了stl的sort 跟 unique.不要在意复杂度(逃 class Solution { public: vector temp; void dfs(vector>& res, vector& candidates, int sum, int pos, int target) { if (sum == target) {
2018-01-28 21:23:09
231
原创 leetcode。 39. Combination Sum
又是dfs水题。 class Solution { public: vector temp; void dfs(vector>& res, vector& candidates, int sum, int pos, int target) { if (sum == target) { res.push_back(temp);
2018-01-28 21:14:16
239
原创 leetcode 37 sudoku solver
emmm暴力dfs。。。真的爆力 class Solution { public: bool isValidSudoku(vector>& board, int x,int y) { int i, j; for (i = 0; i if (i != x && board[i][y] ==
2018-01-28 20:05:09
262
原创 leetcode 36. Valid Sudoku
啊,我还以为求数独呢,原来是求当前的是否符合数独的规范。。 那就横、竖、小九宫格分别判断是否有相同的呗。 class Solution { public: bool isValidSudoku(vector>& board) { unordered_map row, col, all; for (int i = 0; i < 9; ++i) {
2018-01-12 18:52:36
247
原创 codeforces Hello 2018 C. Party Lemonade(贪心)
C. Party Lemonade time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A New Year party is not a New Year party w
2018-01-09 16:33:08
586
原创 codeforces Hello 2018 B. Christmas Spruce
B. Christmas Spruce time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Consider a rooted tree. A rooted tree ha
2018-01-09 15:30:16
383
原创 Codeforces Round #456 (Div. 2) D. Fishes (期望 贪心)
D. Fishes time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output While Grisha was celebrating New Year with Ded Mor
2018-01-06 19:45:28
665
原创 Codeforces Round #456 (Div. 2) B. New Year's Eve (贪心
B. New Year's Eve time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Since Grisha behaved well last year, at Ne
2018-01-06 16:11:51
660
原创 bzoj 1026: [SCOI2009]windy数 (数位dp)
1026: [SCOI2009]windy数 Time Limit: 1 Sec Memory Limit: 162 MB Submit: 8940 Solved: 4048 [Submit][Status][Discuss] Description windy定义了一种windy数。不含前导零且相邻两个数字之差至少为2的正整数被称为windy数。 windy想知道, 在A
2018-01-05 09:51:56
323
原创 bzoj 1024: [SCOI2009]生日快乐
1024: [SCOI2009]生日快乐 Time Limit: 1 Sec Memory Limit: 162 MB Submit: 3081 Solved: 2241 [Submit][Status][Discuss] Description windy的生日到了,为了庆祝生日,他的朋友们帮他买了一个边长分别为 X 和 Y 的矩形蛋糕。现在包括windy ,一共有 N
2018-01-04 13:00:21
321
原创 bozj. 1016: [JSOI2008]最小生成树计数
1016: [JSOI2008]最小生成树计数 Time Limit: 1 Sec Memory Limit: 162 MB Submit: 6702 Solved: 2731 [Submit][Status][Discuss] Description 现在给出了一个简单无向加权图。你不满足于求出这个图的最小生成树,而希望知道这个图中有多少个不同的 最小生成树。(如果两颗最
2018-01-03 20:31:25
394
原创 codeforces。 goodbye 2017。 B. New Year and Buggy Bot
B. New Year and Buggy Bot time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Bob programmed a robot to navigate
2017-12-30 10:21:35
1087
原创 牛客练习赛9。 B 柯朵莉的值域连续端
时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语言262144K 64bit IO Format: %lld 题目描述 珂朵莉给你一个有根树,求有多少个子树满足其内部节点编号在值域上连续 一些数在值域上连续的意思即其在值域上构成一个连续的区间 输入描述: 第一行有一个整数n,表示树的节点数。 接下来n–1行
2017-12-30 08:50:46
362
原创 codeforces 128 B. String
链接:http://codeforces.com/contest/128/problem/B B. String time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard outpu
2017-12-27 09:36:01
593
原创 bzoj 1012: [JSOI2008]最大数maxnumber
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MB Submit: 12032 Solved: 5221 [Submit][Status][Discuss] Description 现在请求你维护一个数列,要求提供以下两种操作:1、 查询操作。语法:Q L 功能:查询当前数列中末尾L 个数中
2017-12-23 21:03:35
216
原创 wannafly 练习8 D加边的无向图
时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit IO Format: %lld 题目描述 给你一个 n 个点,m 条边的无向图,求至少要在这个的基础上加多少条无向边使得任意两个点可达~ 输入描述: 第一行两个正整数 n 和 m 。 接下来的m行中,每行两个正整数 i 、 j ,表示点i与点
2017-12-15 20:41:24
961
原创 wannfly练习赛8 给个n,求1到n的所有数的约数个数的和
时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit IO Format: %lld 题目描述 给个n,求1到n的所有数的约数个数的和~ 输入描述: 第一行一个正整数n 输出描述: 输出一个整数,表示答案 示例1 输入 3 输出 5
2017-12-15 20:39:26
2400
3
原创 HUD 1300 Pearls (水 dp)
Pearls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2908 Accepted Submission(s): 1457 Problem Description In Pearlania everyb
2017-12-10 21:05:11
368
原创 HDU 2059 龟兔赛跑 (区间dp)
龟兔赛跑 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 20636 Accepted Submission(s): 7588 Problem Description 据说在很久很久以前,可怜的兔子经历了人生
2017-12-10 20:37:55
307
原创 poj 3661 runnning 区间dp
Running Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7243 Accepted: 2724 Description The cows are trying to become better athletes, so Bessie is running
2017-12-09 20:38:10
268
原创 poj1651 Multiplication Puzzle(区间dp)
Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11343 Accepted: 7027 Description The multiplication puzzle is played with a row of ca
2017-12-07 11:11:53
220
原创 poj 3280 Cheapest Palindrome
Cheapest Palindrome Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11101 Accepted: 5295 Description Keeping track of all the cows can be a tricky task so
2017-12-07 10:08:32
304
原创 Codeforces Round #449 (Div. 2) B. Chtholly's request (思维
B. Chtholly's request time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output — Thanks a lot for today. — I expe
2017-12-03 11:23:58
477
原创 Codeforces Round #449 (Div. 2). C. Nephren gives a riddle
C. Nephren gives a riddle time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output What are you doing at the end of
2017-12-03 11:20:39
528
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅