自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

Tc的专栏

道阻且长 行则将至

  • 博客(1088)
  • 收藏
  • 关注

原创 Android Open Source Project Patches

注: 以下链接均要翻墙1.Optimize code on get UidDetail in AppDataUsage链接:https://android-review.googlesource.com/#/c/platform/packages/apps/Settings/+/348789/第一个merge的patch,UidDetailProvider提供了关于specif...

2017-10-29 15:02:01 1584

原创 LeetCode 1477 Find Two Non-overlapping Sub-arrays Each With Target Sum (滑动窗)

题目分析:像这种求两段不重复的问题很容易想到分别从左往右,从右往左计算答案再枚举中点。题目大意:求两段不重复的和为target的子串的最小长度和。

2023-12-28 15:47:18 461

原创 LeetCode 1765 Map of Highest Peak (多源点BFS 推荐)

题目分析:多源点bfs,将水的位置都作为源点,每次向四个方向扩散,高度加1,开始一直在想这么做有没有可能出现违反高度差不超过1的限制。其实是不可能的,因为bfs是用队列维护的,特点是先进先出,换句话说,假设当前队首的高度为h,队尾的高度为h+1,不可能出现队尾高度仍为h但队尾高度为h+2的情况,因为处理h+2的前提是所有高度为h的都已处理完毕。题目大意:n*m的矩阵,水的高度为0,地的高度大于0,且要求相邻两个高度差不能超过1,求一种排列方式使得其中的最大值最大。65ms,时间击败91.58%

2022-09-07 23:44:49 249 1

原创 LeetCode 992 Subarrays with K Different Integers (滑动窗 推荐)

题目分析:恰好有k个不好求,但至多有k个则非常容易,恰好k个=至多k个-至多k-1个,至多有k个可以用滑动窗,用hash判断每个数字出现的次数,并用一个值记录当前有多少个不同的数字。题目大意:求恰好有k个不同数字的区间个数。13ms,时间击败88.84%

2022-09-07 08:39:54 267

原创 LeetCode 2400 Number of Ways to Reach a Position After Exactly k Steps (dp 或 组合数 推荐)

联立得x = (endPos - startPos + k) / 2,答案即为C(n, x),取模需要用到除法逆元,由费马小定理a^(p - 1) ≡ 1 mod p。题目分析:最容易想到的是记忆化搜索,dp[i][j]表示从位置i到终点走k步的方案数。设向右走x步,向左走y步,假设endPos比startPos大则。题目大意:直线给两点,从起点到终点走k步的方案数。94ms,时间击败82.98%2ms,时间击败98.14%

2022-09-06 21:17:10 345

原创 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 252

原创 LeetCode 1383 Maximum Performance of a Team (优先队列 贪心 推荐)

You are given two integersnandkand two integer arraysspeedandefficiencyboth of lengthn. There arenengineers numbered from1ton.speed[i]andefficiency[i]represent the speed and efficiency of theithengineer respectively.Chooseat mostkd...

2022-05-08 20:22:54 349

原创 LeetCode 1300 Sum of Mutated Array Closest to Target (前缀和 二分)

Given an integer arrayarrand a target valuetarget, return the integervaluesuch that when we change all the integers larger thanvaluein the given array to be equal tovalue, the sum of the array gets as close as possible (in absolute difference) tot...

2022-05-08 17:57:20 263

原创 LeetCode 1721 Swapping Nodes in a Linked List (链表 快慢指针)

You are given theheadof a linked list, and an integerk.Returnthe head of the linked list afterswappingthe values of thekthnode from the beginning and thekthnode from the end (the list is1-indexed).Example 1:Input: head = [1,2,3,4,5], k ...

2022-05-07 21:24:15 348

原创 LeetCode 994 Rotting Oranges (bfs 推荐)

You are given anm x ngridwhere each cell can have one of three values:0representing an empty cell, 1representing a fresh orange, or 2representing a rotten orange.Every minute, any fresh orange that is4-directionally adjacentto a rotten orange ...

2022-05-07 16:19:35 232

原创 LeetCode 452 Minimum Number of Arrows to Burst Balloons (贪心,排序)

There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer arraypointswherepoints[i] = [xstart, xend]denotes a balloon whosehorizontal diameterstretches betweenxstartandxend....

2022-05-07 15:53:14 183

原创 LeetCode 1035 Uncrossed Lines(dp 推荐)

You are given two integer arraysnums1andnums2. We write the integers ofnums1andnums2(in the order they are given) on two separate horizontal lines.We may draw connecting lines: a straight line connecting two numbersnums1[i]andnums2[j]such that...

2022-05-07 10:13:48 166

原创 LeetCode 2131 Longest Palindrome by Concatenating Two Letter Words (hash)

You are given an array of stringswords. Each element ofwordsconsists oftwolowercase English letters.Create thelongest possible palindromeby selecting some elements fromwordsand concatenating them inany order. Each element can be selectedat mos...

2022-05-05 19:58:47 363

原创 LeetCode 838 Push Dominoes (二点法,模拟)

There arendominoes in a line, and we place each domino vertically upright. In the beginning, we simultaneously push some of the dominoes either to the left or to the right.After each second, each domino that is falling to the left pushes the adjacent d..

2022-04-30 17:37:43 309

原创 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 597

原创 LeetCode 1233 Remove Sub-Folders from the Filesystem (Trie)

Given a list of foldersfolder, returnthe folders after removing allsub-foldersin those folders. You may return the answer inany order.If afolder[i]is located within anotherfolder[j], it is called asub-folderof it.The format of a path is one o...

2022-04-03 22:52:28 579

原创 LeetCode 990 Satisfiability of Equality Equations (并查集 推荐)

You are given an array of stringsequationsthat represent relationships between variables where each stringequations[i]is of length4and takes one of two different forms:"xi==yi"or"xi!=yi".Here,xiandyiare lowercase letters (not necessarily diffe...

2022-03-20 15:42:57 424

原创 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 608

原创 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 452

原创 LeetCode 688 Knight Probability in Chessboard (概率dp)

On ann x nchessboard, a knight starts at the cell(row, column)and attempts to make exactlykmoves. The rows and columns are0-indexed, so the top-left cell is(0, 0), and the bottom-right cell is(n - 1, n - 1).A chess knight has eight possible move...

2022-03-19 11:09:12 372

原创 LeetCode 1054 Distant Barcodes (排序 贪心)

In a warehouse, there is a row of barcodes, where the ith barcode is barcodes[i].Rearrange the barcodes so that no two adjacent barcodes are equal. You may return any answer, and it is guaranteed an answer exists.Example 1:Input: barcodes = [1,1,1,2

2022-03-18 16:55:07 343

原创 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 944

原创 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 870

原创 LeetCode 881 Boats to Save People (两点法)

You are given an arraypeoplewherepeople[i]is the weight of theithperson, and aninfinite number of boatswhere each boat can carry a maximum weight oflimit. Each boat carries at most two people at the same time, provided the sum of the weight of tho...

2022-03-09 10:16:05 109

原创 LeetCode 59 Spiral Matrix II (模拟)

Given a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order.Example 1:Input: n = 3Output: [[1,2,3],[8,9,4],[7,6,5]]Example 2:Input: n = 1Output: [[1]]Constraints:1 <= n <= 20题目链接:https:/

2022-03-02 17:03:43 139

原创 LeetCode 652 Find Duplicate Subtrees (dfs 推荐)

Given therootof a binary tree, return allduplicate subtrees.For each kind of duplicate subtrees, you only need to return the root node of anyoneof them.Two trees areduplicateif they have thesame structurewith thesame node values.Example 1:...

2022-02-28 20:15:17 156

原创 LeetCode 430 Flatten a Multilevel Doubly Linked List (dfs 链表)

You are given a doubly linked list, which contains nodes that have a next pointer, a previous pointer, and an additionalchild pointer. This child pointer may or may not point to a separate doubly linked list, also containing these special nodes. These chi.

2022-02-28 20:03:45 317

原创 LeetCode 1749 Maximum Absolute Sum of Any Subarray (dp)

You are given an integer arraynums. Theabsolute sumof a subarray[numsl, numsl+1, ..., numsr-1, numsr]isabs(numsl+ numsl+1+ ... + numsr-1+ numsr).Returnthemaximumabsolute sum of any(possibly empty)subarray ofnums.Note thatabs(x)is defin...

2022-02-28 18:42:50 166

原创 LeetCode 1261 Find Elements in a Contaminated Binary Tree (递归)

Given a binary tree with the following rules:root.val == 0 IftreeNode.val == xandtreeNode.left != null, thentreeNode.left.val == 2 * x + 1 IftreeNode.val == xandtreeNode.right != null, thentreeNode.right.val == 2 * x + 2Now the binary tree is ...

2022-02-26 14:18:48 309

原创 LeetCode 1609 Even Odd Tree (bfs)

A binary tree is namedEven-Oddif it meets the following conditions:The root of the binary tree is at level index0, its children are at level index1, their children are at level index2, etc. For everyeven-indexedlevel, all nodes at the level have...

2022-02-25 12:14:00 123

原创 LeetCode 1094 Car Pooling (模拟)

There is a car withcapacityempty seats. The vehicle only drives east (i.e., it cannot turn around and drive west).You are given the integercapacityand an arraytripswheretrips[i] = [numPassengersi, fromi, toi]indicates that theithtrip hasnumPas...

2022-02-24 21:23:23 190

原创 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 221

原创 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 198

原创 LeetCode 665 Non-decreasing Array (贪心)

Given an arraynumswithnintegers, your task is to check if it could become non-decreasing by modifyingat most one element.We define an array is non-decreasing ifnums[i] <= nums[i + 1]holds for everyi(0-based) such that (0 <= i <= n - 2)....

2022-02-22 21:25:48 161

原创 LeetCode 1010 Pairs of Songs With Total Durations Divisible by 60 (hash)

You are given a list of songs where theithsong has a duration oftime[i]seconds.Returnthe number of pairs of songs for which their total duration in seconds is divisible by60. Formally, we want the number of indicesi,jsuch thati < jwith(tim...

2022-02-22 20:48:47 209

原创 LeetCode 1024 Video Stitching (dp,jump game)

You are given a series of video clips from a sporting event that lastedtimeseconds. These video clips can be overlapping with each other and have varying lengths.Each video clip is described by an arrayclipswhereclips[i] = [starti, endi]indicates t...

2022-02-22 12:49:50 198

原创 LeetCode 1116 Print Zero Even Odd (并发 多线程 CountDownLatch Lock Condition)

You have a functionprintNumberthat can be called with an integer parameter and prints it to the console.For example, callingprintNumber(7)prints7to the console.You are given an instance of the classZeroEvenOddthat has three functions:zero,even...

2022-02-20 08:30:53 188

原创 LeetCode 2054 Two Best Non-Overlapping Events (排序 二分)

You are given a0-indexed2D integer array ofeventswhereevents[i] = [startTimei, endTimei, valuei]. Theithevent starts atstartTimeiand ends atendTimei, and if you attend this event, you will receive a value ofvaluei. You can chooseat mosttwonon...

2022-02-19 14:59:33 375

原创 LeetCode 698 Partition to K Equal Sum Subsets (dfs 剪枝)

Given an integer array nums and an integer k, return true if it is possible to divide this array into k non-empty subsets whose sums are all equal.Example 1:Input: nums = [4,3,2,3,5,2,1], k = 4Output: trueExplanation: It is possible to divide it int

2022-02-18 21:01:14 243

原创 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 451

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除