![](https://img-blog.csdnimg.cn/2019092715111047.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
套路思维题
文章平均质量分 68
前后缀和,排序之类的
_TCgogogo_
这个作者很懒,什么都没留下…
展开
-
LeetCode 1423 Maximum Points You Can Obtain from Cards (前缀和)
There are several cardsarranged in a row, and each card has an associated number of points. The points are given in the integer arraycardPoints.In one step, you can take one card from the beginning or from the end of the row. You have to take exactlyk...原创 2022-05-09 22:36:24 · 258 阅读 · 0 评论 -
LeetCode 1590 Make Sum Divisible by P (前缀和 hash)
Given an array of positive integersnums, remove thesmallestsubarray (possiblyempty) such that thesumof the remaining elements is divisible byp. It isnotallowed to remove the whole array.Returnthe length of the smallest subarray that you need to...原创 2022-04-03 23:48:56 · 607 阅读 · 0 评论 -
LeetCode 1975 Maximum Matrix Sum (贪心)
You are given ann x nintegermatrix. You can do the following operationanynumber of times:Choose any twoadjacentelements ofmatrixandmultiplyeach of them by-1.Two elements are consideredadjacentif and only if they share aborder.Your goal ...原创 2022-03-20 14:24:24 · 622 阅读 · 0 评论 -
LeetCode 1524 Number of Sub-arrays With Odd Sum (前缀和)
Given an array of integersarr, returnthe number of subarrays with anoddsum.Since the answer can be very large, return it modulo10^9+7.Example 1:Input: arr = [1,3,5]Output: 4Explanation: All subarrays are [[1],[1,3],[1,3,5],[3],[3,5],[5]]All ...原创 2022-03-19 15:59:57 · 464 阅读 · 0 评论 -
LeetCode 1685 Sum of Absolute Differences in a Sorted Array (前缀和)
You are given an integer arraynumssorted innon-decreasingorder.Build and returnan integer arrayresultwith the same length asnumssuch thatresult[i]is equal to thesummation of absolute differencesbetweennums[i]and all the other elements in t...原创 2022-03-16 16:43:23 · 953 阅读 · 0 评论 -
LeetCode 456 132 Pattern (单调栈 推荐)
Given an arrayofnintegersnums, a132 patternis a subsequence of three integersnums[i],nums[j]andnums[k]such thati < j < kandnums[i] < nums[k] < nums[j].Returntrueif there is a132 patterninnums, otherwise, returnfalse.Exam...原创 2022-03-11 15:47:00 · 880 阅读 · 0 评论 -
LeetCode 2171 Removing Minimum Number of Magic Beans (前缀和 推荐)
You are given an array ofpositiveintegersbeans, where each integer represents the number of magic beans found in a particular magic bag.Removeany number of beans (possibly none) from each bag such that the number of beans in each remainingnon-empty...原创 2022-02-24 20:38:24 · 238 阅读 · 0 评论 -
LeetCode 1567 Maximum Length of Subarray With Positive Product (递推? 推荐)
Given an array of integersnums, find the maximum length of a subarray where the product of all its elements is positive.A subarray of an array is a consecutive sequence of zero or more values taken out of that array.Returnthe maximum length of a suba..原创 2022-02-23 12:33:29 · 207 阅读 · 0 评论 -
LeetCode 1248 Count Number of Nice Subarrays (哈希 推荐)
Given an array of integersnumsand an integerk. A continuous subarray is calledniceif there arekodd numbers on it.Returnthe number ofnicesub-arrays.Example 1:Input: nums = [1,1,2,1,1], k = 3Output: 2Explanation: The only sub-arrays with 3...原创 2022-02-17 15:32:34 · 459 阅读 · 0 评论 -
LeetCode 1605 Find Valid Matrix Given Row and Column Sums (思维 构造 推荐)
You are given two arraysrowSumandcolSumof non-negative integers whererowSum[i]is the sum of the elements in theithrow andcolSum[j]is the sum of the elements of thejthcolumn of a 2D matrix. In other words, you do not know the elements of the mat...原创 2022-02-17 15:23:21 · 299 阅读 · 0 评论 -
LeetCode 1814 Count Nice Pairs in an Array (map 推荐)
You are given an arraynumsthat consists of non-negative integers. Let us definerev(x)as the reverse of the non-negative integerx. For example,rev(123) = 321, andrev(120) = 21. A pair of indices(i, j)isniceif it satisfies all of the following con...原创 2022-02-09 12:59:03 · 463 阅读 · 0 评论 -
LeetCode 768. Max Chunks To Make Sorted II (思维)
You are given an integer arrayarr.We splitarrinto some number ofchunks(i.e., partitions), and individually sort each chunk. After concatenating them, the result should equal the sorted array.Returnthe largest number of chunks we can make to sort ...原创 2022-01-24 21:17:11 · 104 阅读 · 0 评论 -
LeetCode 229 Majority Element II (投票算法)
Given an integer array of sizen, find all elements that appear more than⌊ n/3 ⌋times.Example 1:Input: nums = [3,2,3]Output: [3]Example 2:Input: nums = [1]Output: [1]Example 3:Input: nums = [1,2]Output: [1,2]Constraints:1 <= n...原创 2021-11-01 22:15:17 · 207 阅读 · 0 评论 -
Codeforce 1151D Stas and the Queue at the Buffet (公式推导 排序)
D. Stas and the Queue at the Buffettime limit per test:1 secondmemory limit per test:256 megabytesDuring a break in the buffet of the scientific lyceum of the Kingdom of Kremland, there was forme...原创 2020-04-12 17:31:55 · 260 阅读 · 0 评论 -
Codeforces 102394I Interesting Permutation (脑洞)
I. Interesting Permutationtime limit per test 1 secondmemory limit per test 512 megabytesDreamGrid has an interesting permutation of 1,2,…,n denoted by a1,a2,…,an. He generates three sequences f,...原创 2019-11-09 17:49:30 · 641 阅读 · 0 评论 -
LeetCode 523 Continuous Subarray Sum (同余)
LeetCode 523 Continuous Subarray Sum (同余)原创 2017-07-14 19:58:08 · 1050 阅读 · 0 评论 -
LeetCode 621 Task Scheduler (贪心 思维 推荐)
Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks. Tasks could be done without original order. Each task could ...原创 2019-03-26 01:37:11 · 218 阅读 · 0 评论 -
SDUT 3308 最长01串
最长01串Time Limit: 2666 ms; Memory Limit: 65536 KiBProblem Description给定一个0-1串,请找到一个尽可能长的连续子串,其中包含的0与1的个数相等。组数很多,注意常数优化。。。Input 一个字符串,只包含01,长度不超过1000000Output 一行一个整数,最长的0与1的个数相等的子串的长度。S...原创 2018-10-19 00:11:19 · 202 阅读 · 0 评论 -
LeetCode 41 First Missing Positive (思维)
Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant spa原创 2018-01-15 14:18:10 · 259 阅读 · 0 评论 -
HDU 6092 Rikka with Subset (背包 思维)
HDU 6092 Rikka with Subset (背包 思维)原创 2017-08-11 14:24:37 · 717 阅读 · 0 评论 -
Codeforces 798D Mike and distribution (构造 + 脑洞 推荐)
Codeforces 798D Mike and distribution (构造 + 脑洞 推荐)原创 2017-08-03 09:42:17 · 784 阅读 · 0 评论 -
Codeforces 798C Mike and gcd problem (贪心)
Codeforces 798C Mike and gcd problem (贪心)原创 2017-08-03 08:51:33 · 702 阅读 · 0 评论 -
LeetCode 36 Valid Sudoku (O(1)空间 位运算)
LeetCode 36 Valid Sudoku (O(1)空间 位运算)原创 2017-07-07 14:18:32 · 504 阅读 · 0 评论 -
2019 ICPC World Finals A Azulejos (贪心 排序)
AzulejosAzulejo in the cathedral of Porto. Source:Wikimedia CommonsCeramic artists Maria and João are opening a smallazulejostore in Porto.Azulejosare the beautiful ceramic tiles for which Po...原创 2019-04-05 11:27:59 · 2238 阅读 · 0 评论 -
LeetCode 659 Split Array into Consecutive Subsequences (hash 思维 推荐)
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....原创 2019-04-01 01:44:10 · 134 阅读 · 0 评论 -
LeetCode 1014 Best Sightseeing Pair (思维 推荐)
Given an arrayAof positive integers,A[i]represents the value of thei-th sightseeing spot, and twosightseeing spotsiandjhave distancej - ibetween them.Thescoreof a pair (i < j) of sig...原创 2019-05-30 16:33:40 · 184 阅读 · 0 评论 -
LeetCode 503 Next Greater Element II (数组)
Given a circular array (the next element of the last element is the first element of the array), print the Next Greater Number for every element. The Next Greater Number of a number x is the first gre...原创 2019-05-15 19:27:33 · 174 阅读 · 0 评论 -
Codeforces B Cat Party (思维 推荐)
B2. Cat Party (Hard Edition)time limit per test:1 secondmemory limit per test:256 megabytesThis problem is same as the previous one, but has larger constraints.Shiro's just moved to the new...原创 2019-05-13 20:04:32 · 481 阅读 · 0 评论 -
LeetCode 1025 Divisor Game (博弈)
Alice and Bob take turns playing a game, with Alice starting first.Initially, there is a numberNon the chalkboard. On each player's turn, that player makes amoveconsisting of:Choosinganyxw...原创 2019-05-05 11:01:52 · 665 阅读 · 0 评论 -
LeetCode 650 2 Keys Keyboard (dp 推荐)
Initially on a notepad only one character 'A' is present. You can perform two operations on this notepad for each step:Copy All: You can copy all the characters present on the notepad (partial copy ...原创 2019-04-29 02:24:49 · 168 阅读 · 0 评论 -
LeetCode 739 Daily Temperatures (思维)
Given a list of daily temperaturesT, 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...原创 2019-04-27 15:16:31 · 194 阅读 · 0 评论 -
LeetCode 448 Find All Numbers Disappeared in an Array (思维 推荐)
Given an array of integers where 1 ≤ a[i] ≤n(n= size of array), some elements appear twice and others appear once.Find all the elements of [1,n] inclusive that do not appear in this array.Coul...原创 2019-04-21 13:08:13 · 107 阅读 · 0 评论 -
LeetCode 467 Unique Substrings in Wraparound String (思维题)
LeetCode 467 Unique Substrings in Wraparound String (思维)原创 2017-07-05 14:25:40 · 661 阅读 · 0 评论 -
LeetCode 462 Minimum Moves to Equal Array Elements II (中位数)
LeetCode 462 Minimum Moves to Equal Array Elements II (中位数)原创 2017-01-06 15:44:38 · 489 阅读 · 0 评论 -
趋势科技笔试题 DNA串查重 (4进制)
趋势科技笔试题 DNA串查重 (4进制)原创 2016-11-13 20:03:45 · 1120 阅读 · 0 评论 -
UVALive 7511 Multiplication Table (数学模拟题)
UVALive 7511 Multiplication Table (数学模拟题)原创 2016-03-31 22:47:39 · 1344 阅读 · 0 评论 -
ECfinal UVALive 7512 November 11th (公式)
ECfinal UVALive 7512 November 11th (公式)原创 2016-03-31 22:42:51 · 967 阅读 · 0 评论 -
POJ 3572 Hanoi Towers (YY + 推公式)
POJ 3572 Hanoi Towers (YY + 推公式)原创 2015-10-08 12:20:05 · 952 阅读 · 0 评论 -
POJ 3566 Building for UN (无脑构造 水题)
POJ 3566 Building for UN (无脑构造 水题)原创 2015-10-08 11:38:13 · 714 阅读 · 0 评论 -
HDU 5319 Painter (模拟 脑洞题)
HDU 5319 Painter (模拟 脑洞题)原创 2015-07-28 18:52:14 · 1573 阅读 · 0 评论