
leetcode and lintcode
文章平均质量分 54
SomeOtherTime
这个作者很懒,什么都没留下…
展开
-
Manacher算法
思路:Manacher算法在O(n)时间复杂度求所有回文子串。思路为:当求后面某一位为中心时的回文子串时,对前面的回文字串信息的复用。类似KMP。本质还是动态规划。考虑到回文子串长度还有奇数或偶数,需要对原字符串S进行预处理,插值为另一个字符串T(插值方式见网上资料)。当T中以原字符串的字符为中心时对应奇数子串,以插入的字符“#”为中心时对应偶数子串。之后在将T中包含的回文信息,转换回S的回文信息(从起始字符的对应关系和长度的对应关系,转换到原字符串的回文子串)。参考:https://www原创 2021-08-13 00:15:07 · 118 阅读 · 0 评论 -
leetcode 1825. Finding MK Average
https://leetcode.com/problems/finding-mk-average/You are given two integers,mandk, and a stream of integers. You are tasked to implement a data structure that calculates theMKAveragefor the stream.TheMKAveragecan be calculated using these steps:...原创 2021-04-13 00:51:46 · 410 阅读 · 0 评论 -
lintcode 1755. 和的路径(meet in the middle)
描述中文English有一个n×m的矩阵,和一个目标值k。你需要从[1,1]开始走到到[n,m],只能向下或者向右走,经过的路径上的和记为f。现在你需要计算有多少条路径使得f=k。1 \leq n, m \leq 201≤n,m≤20 1 \leq rec[i][j] \leq 10000000001≤rec[i][j]≤1000000000 k \leq 10000000...原创 2019-12-21 17:38:57 · 257 阅读 · 0 评论 -
lintcode 948. 序列计数
https://www.lintcode.com/problem/sequence-count/description求有多少个长为n的序列满足如下要求:序列中的数都是不超过m的正整数 这n个数的和是p的倍数 这n个数中至少有一个是质数返回满足要求的序列个数对 10000007 取模的结果1 <= n <= 10^9 1 <= m &...原创 2019-12-02 18:51:08 · 502 阅读 · 0 评论 -
lintcode 1384. 段式石子归并
https://www.lintcode.com/problem/segment-stones-merge/有一个石子归并的游戏。最开始的时候,有n堆石子排成一列,目标是要将所有的石子合并成一堆。合并规则如下:每一次可以合并连续x堆石子,left <= x <= right 每次合并的代价为所合并的x堆石子的重量之和求出最小的合并代价,如果无法完成合并返回0。...原创 2019-12-02 12:03:11 · 304 阅读 · 0 评论 -
leetcode 1244. Design A Leaderboard
Design a Leaderboard class, which has 3 functions:addScore(playerId, score): Update the leaderboard by addingscoreto the given player's score. If there is no player with such id in the leaderboard...原创 2019-11-03 16:58:25 · 1246 阅读 · 0 评论 -
leetcode 1246. Palindrome Removal
Given an integer arrayarr, in one move you can select apalindromicsubarrayarr[i], arr[i+1], ..., arr[j]wherei <= j, and remove that subarray from the given array. Note that after removing a s...原创 2019-11-03 13:48:17 · 1495 阅读 · 0 评论 -
leetcode 732. My Calendar III(线段树)
Implement aMyCalendarThreeclass to store your events. A new event canalwaysbe added.Your class will have one method,book(int start, int end). Formally, this represents a booking on the half ope...原创 2019-03-06 23:29:59 · 486 阅读 · 0 评论 -
leetcode 664. Strange Printer 546. Remove Boxes
There is a strange printer with the following two special requirements:The printer can only print a sequence of the same character each time. At each turn, the printer can print new characters star...原创 2019-02-20 17:06:59 · 262 阅读 · 0 评论 -
leetcode 214. Shortest Palindrome (KMP)
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.Example 1:...原创 2019-02-25 02:40:56 · 161 阅读 · 0 评论 -
leetcode 372. Super Pow
Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.Example 1:Input: a = 2, b = [3]Output: 8Example ...原创 2019-02-09 19:45:57 · 229 阅读 · 0 评论 -
leetcode 480. Sliding Window Median
Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.Examples: [2,3,4] , the median i...原创 2019-01-10 00:47:09 · 280 阅读 · 0 评论 -
lintcode 43. Maximum Subarray III
给定一个整数数组和一个整数k,找出k个不重叠子数组使得它们的和最大。每个子数组的数字在数组中的位置应该是连续的。返回最大的和。Example样例1输入: List = [1,2,3]k = 1输出: 6说明: 1 + 2 + 3 = 6样例2输入:List = [-1,4,-2,3,-2,3]k = 2输出: 8说明: 4 + (3 + -2 +...原创 2019-05-28 01:50:30 · 342 阅读 · 0 评论 -
leetcode 474. Ones and Zeroes(背包问题)
In the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue.For now, suppose you are a dominator of m 0s and n 1s respectively. On the other ...原创 2018-12-25 16:56:36 · 399 阅读 · 0 评论 -
记录 (待做)
623. K步编辑1381. 最大线段覆盖(完成)753.Cracking the Safe De Bruijn sequenceredis http://download.redis.io/releases/模板import java.util.*;import java.io.*;public class Main { publi...转载 2019-03-20 17:13:21 · 218 阅读 · 0 评论 -
lintcode 1684. K-wolf数
1684.K-wolf数CAT 专属题目中文EnglishAlice认为整数x是K-wolf数,如果x的十进制表示中的每k个相邻数字都是不同的。给定(l,r,k),请计算在[l,r]范围内有多少个K-Wolf数。样例样例 1:输入: l=1,r=1,k=2输出: 1解释:1是2-wolf数。样例 2:输入: l=20,r=100,k=5输出:72...原创 2019-05-24 17:00:17 · 579 阅读 · 0 评论 -
lintcode 1695. Kanade的三重奏
给你一个数组A [1..n],你需要计算多少三元组(i,j,k)满足(i <j <k)和((A [i] xor A [j])<(A [j] xor A [k]))样例样例 1:输入:[1,2,3,4,5]输出:6解释:[1,2,4],[1,2,5],[1,3,4],[1,3,5],[2,3,4],[2,3,5]符合要求。样例 2:输入:[1,2,3]...原创 2019-05-25 22:06:55 · 449 阅读 · 0 评论 -
lintcode 1381. 最大线段覆盖
在一个数轴上给出n个线段,问选择不超过k个线段,使得这k个线段覆盖的数最多。样例样例1输入:[(1,2),(2,3),(3,4)]2输出: 4说明:选择线段(1,2),(3,4)可以覆盖1,2,3,4这个4个数。样例2输入:[(1,2),(2,3),(1,7)]2输出: 7说明:选择线段(1,7)可以覆盖1,2,3,4,5,6,7这个7个数。注意...原创 2019-07-04 23:07:34 · 687 阅读 · 0 评论 -
一些不错的题
https://leetcode.com/problems/bricks-falling-when-hit/https://leetcode.com/problems/remove-boxes/https://leetcode.com/problems/cherry-pickup/https://leetcode.com/problems/cat-and-mouse/...原创 2019-08-09 13:39:45 · 129 阅读 · 0 评论 -
leetcode 1157. Online Majority Element In Subarray
Implementing the classMajorityChecker, which has the following API:MajorityChecker(int[] arr)constructs an instance of MajorityChecker with the given arrayarr; int query(int left, int right, int...原创 2019-09-06 07:13:38 · 369 阅读 · 0 评论 -
leetcode 1192. Critical Connections in a Network 与 CF1000E. We Need More Bosses
There arenservers numbered from0ton-1connected byundirected server-to-serverconnectionsforming a network whereconnections[i] = [a, b]represents a connection between serversaandb. Any ser...原创 2019-09-15 22:57:41 · 2459 阅读 · 0 评论 -
leetcode 84. Largest Rectangle in Histogram
Given n non-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 where width of each ...原创 2018-05-07 20:53:43 · 113 阅读 · 0 评论 -
lintcode 1251. 拆分子数组
1251. 拆分子数组给定一个由非负整数和整数m组成的数组,可以将数组拆分为m个非空连续子数组。编写算法以最小化这些m个子阵列中的最大总和。样例输入:nums = [7,2,5,10,8]m = 2输出:18解析:将nums拆分成子数组的方式有4种.最好的选择是拆分成 [7,2,5] 和 [10,8],两个子数组中的最大的和只有 18.注意事项如果n是数...原创 2018-12-30 21:30:06 · 681 阅读 · 0 评论 -
lintcode 1686. 雪地靴
n块砖,第i块砖积雪f[i]英尺。b双靴子,编号从0到b-1,第i双靴子能在至多s[i]英尺深的积雪行走,步长最多为d[i]。每次可以选择不换靴子继续走,或者丢弃当前的靴子换上当前编号最小的靴子,或者丢弃当前编号最小的靴子,求走到最后一块砖最小丢弃的靴子数。样例给定 n=10, b=4, f=[0,2,8,3,6,7,5,1,4,0], s=[2,4,3,7], d=[3,2,4,1], ...原创 2018-12-30 07:46:08 · 625 阅读 · 0 评论 -
leetcode 363. Max Sum of Rectangle No Larger Than K
Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix such that its sum is no larger than k.Example:Input: matrix = [[1,0,1],[0,-2,3]], k = 2Output: ...原创 2018-12-28 03:52:37 · 114 阅读 · 0 评论 -
leetcode 301. Remove Invalid Parentheses
Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results.Note: The input string may contain letters other than the parentheses ( and )....原创 2018-09-19 01:43:53 · 132 阅读 · 0 评论 -
leetcode 315. Count of Smaller Numbers After Self
You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i]is the number of smaller elements to the right of nums[i].Example:...原创 2018-07-02 01:32:40 · 373 阅读 · 0 评论 -
leetcode 72. Edit Distance
Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2.You have the following 3 operations permitted on a word:Insert a character Delete a chara...原创 2018-05-15 17:27:07 · 126 阅读 · 0 评论 -
leetcode 659. Split Array into Consecutive Subsequences
You are given an integer array sorted in ascending order (may contain duplicates), you need to split them into several subsequences, where each subsequences consist of at least 3 consecutive integers....原创 2018-04-29 21:42:28 · 535 阅读 · 0 评论 -
leetcode 135. Candy
There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least one ca...原创 2018-05-12 23:50:55 · 230 阅读 · 0 评论 -
leetcode 188. Best Time to Buy and Sell Stock IV
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most k transactions.Note:You may not eng...原创 2018-05-18 03:12:53 · 232 阅读 · 0 评论 -
leetcode 146. LRU Cache
=======================2019.1.18====================双向链表+hashmap。双向链表存key的先后顺序消息,hashmap快速定位元素。class LRUCache { Node first; Node end; final int K; int cap; HashMap<Integer,...原创 2018-04-08 01:00:37 · 602 阅读 · 0 评论 -
leetcode 472. Concatenated Words
Given a list of words (without duplicates), please write a program that returns all concatenated words in the given list of words.A concatenated word is defined as a string that is comprised entirel...原创 2018-10-04 21:07:01 · 256 阅读 · 0 评论 -
leetcode 460. LFU Cache
Design and implement a data structure for Least Frequently Used (LFU) cache. It should support the following operations: get and put.get(key) - Get the value (will always be positive) of the key if ...原创 2018-10-12 05:56:36 · 308 阅读 · 0 评论 -
leetcode 307. Range Sum Query - Mutable
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.The update(i, val) function modifies nums by updating the element at index i to val.Example:...原创 2018-11-03 02:33:03 · 269 阅读 · 0 评论 -
leetcode 30. Substring with Concatenation of All Words
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and wi...原创 2018-12-22 03:13:03 · 120 阅读 · 0 评论 -
leetcode 355. Design Twitter
Design a simplified version of Twitter where users can post tweets, follow/unfollow another user and is able to see the 10 most recent tweets in the user's news feed. Your design should support the fo...原创 2018-12-17 01:41:55 · 241 阅读 · 0 评论 -
leetcode 678. Valid Parenthesis String
Given a string containing only three types of characters: '(', ')' and '*', write a function to check whether this string is valid. We define the validity of a string by these rules:Any left parenth...原创 2018-12-16 00:45:30 · 484 阅读 · 0 评论 -
leetcode 310. Minimum Height Trees
For an undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with minimum height are called min...原创 2018-12-21 04:23:45 · 135 阅读 · 0 评论 -
lintcode 1671.玩游戏
描述控制台1671. 玩游戏cat-only-iconCAT 专属题目n个人在玩游戏,每局游戏有一个裁判和n-1个玩家。A数组表示每个人都想当玩家至少Ai(0<=i<n)次。请你求出最少进行游戏的数量。样例input:A=[2,2,2,2]output:ans=3注意事项∑Ai<=1e18n>1思路:裁判每次找最小的那个当选,当一次裁判等于其...原创 2018-12-26 16:05:39 · 2342 阅读 · 6 评论