- 博客(33)
- 收藏
- 关注
转载 LeetCode 1168. Optimize Water Distribution in a Village
题目描述:There arenhouses in a village. We want to supply water for all the houses by building wells and laying pipes.For each housei, we can either build a well inside it directly with costw...
2019-08-26 23:02:00
278
转载 Leetcode 1162. As Far from Land as Possible
题目描述:Given an N x Ngridcontaining only values0and1, where0represents waterand1represents land, find a water cell such that its distance to the nearest land cell is maximized and re...
2019-08-18 15:16:00
158
转载 LeetCode 1102. Path With Maximum Minimum Value
Problem Description:Given amatrix of integersAwithRrows andCcolumns, findthemaximumscoreof a path starting at[0,0]and ending at[R-1,C-1].Thescoreof a path is theminimumvalue...
2019-07-07 15:25:00
265
转载 LeetCode 549. Binary Tree Longest Consecutive Sequence II
Given a binary tree, you need to find the length of Longest Consecutive Path in Binary Tree.Especially, this path can be either increasing or decreasing. For example, [1,2,3,4] and [4,3,2,1] ar...
2019-06-26 21:44:00
156
转载 LeetCode 1090. Largest Values From Labels
Problem Description: We have a set of items: thei-th item has valuevalues[i]and labellabels[i].Then, we choosea subsetSof these items, such that:|S| <= num_wantedFor every label...
2019-06-17 00:13:00
57
转载 LeetCode 435. Non-overlapping Intervals
Problem Description:Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.Note:You may assume th...
2019-06-15 00:54:00
84
转载 LeetCode 298. Binary Tree Longest Consecutive Sequence
Problem Description:Given a binary tree, find the length of the longest consecutive sequence path.The path refers to any sequence of nodes from some starting node to any node in the tree alon...
2019-06-05 21:39:00
144
转载 LeetCode 114. Flatten Binary Tree to Linked List
Problem Description:Given a binary tree, flatten it to a linked list in-place.For example, given the following tree: 1 / \ 2 5 / \ \3 4 6The flattened tree should ...
2019-06-03 15:47:00
78
转载 剑指 offer 1+2+3+4+...+n
问题描述:求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。题解:采用递归算法,利用短路机制来解决终止条件的问题public int Sum_Solution(int n) { int Sum = n; boolean t = (n > 0) ...
2019-05-24 21:32:00
172
转载 LeetCode 1043. Partition Array for Maximum Sum
Problem description:Given an integer arrayA, you partition the array into (contiguous) subarrays of length at mostK. After partitioning, each subarray has their values changed to become the ...
2019-05-12 15:39:00
61
转载 LeetCode 186. Reverse Words in a String II
Problem description:Given an input string, reverse the string word by word.Example:Input: ["t","h","e"," ","s","k","y"," ","i","s"," ","b","l","u","e"]inter : ["e","u","l","b"," "...
2019-04-22 10:52:00
105
转载 LeetCode 1032. Stream of Characters
Problem Description:Implement theStreamCheckerclass as follows:StreamChecker(words): Constructor, init the data structure with the given words.query(letter): returns true if and only i...
2019-04-21 20:25:00
85
转载 LeetCode 333. Largest BST Subtree
Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest means subtree with largest number of nodes in it.Note:A subtree must include all of its descenda...
2019-04-20 13:04:00
94
转载 LeetCode 370. Range Addition
Assume you have an array of lengthninitialized with all0's and are givenkupdate operations.Each operation is represented as a triplet:[startIndex, endIndex, inc]which increments each elem...
2019-04-17 10:06:00
103
转载 LeetCode 581. Shortest Unsorted Continuous Subarray
Given an integer array, you need to find onecontinuous subarraythat if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too.You need to ...
2019-04-16 11:05:00
77
转载 LeetCode 525. Contiguous Array
Problem Description:Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1.题解:这个题很容易想到复杂度为O(n^2)的暴力方法。看了提示HashMap后想了大概半个小时想到了O(n)的解法。我的想法是用Has...
2019-03-29 17:00:00
78
转载 LeetCode 713. Subarray Product Less Than K
Problem Description:Your are given an array of positive integersnums.Count and print the number of (contiguous) subarrays where the product of all the elements in the subarray is less thank...
2019-03-29 14:05:00
96
转载 523. Continuous Subarray Sum
Problem Description:Given a list ofnon-negativenumbers and a targetintegerk, write a function to check if the array has a continuous subarray of size at least 2 that sums up to the multiple...
2019-03-28 20:49:00
79
转载 LeetCode 95. Unique Binary Search Trees II
Problem Description:Given an integern, generate all structurally uniqueBST's(binary search trees) that store values 1 ...n.给定一个整数n,生成所有不同的二叉搜索树,其节点存储所有从1到n的值。此题是96题的follow up,96题采用动态规划...
2019-03-23 14:54:00
97
转载 LeetCode 731. My Calendar II
Problem Description:Implement aMyCalendarTwoclass to store your events. A new event can be added if adding the event will not cause atriplebooking.Your class will have one method,book(i...
2019-03-16 18:19:00
118
转载 LeetCode 729 My Calendar I
Problem description: Implement aMyCalendarclass to store your events. A new event can be added if adding the event will not cause a double booking.Your class will have the method,book(int st...
2019-03-15 22:29:00
107
转载 LeetCode 84. Largest Rectangle in Histogram
Problem Description:Givennnon-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.解题思路:面积的计算肯定是...
2019-03-12 15:59:00
104
转载 Leetcode 1005. Maximize Sum Of Array After K Negations
Problem Description:Given an arrayAof integers, wemustmodify the array in the following way: we choose aniand replaceA[i]with-A[i], and we repeat this processKtimes in total. (We ma...
2019-03-11 13:17:00
61
转载 Beautiful Numbers KickStart 2017 Round2
ProblemWe consider a number to bebeautifulif it consists only of the digit 1 repeated one or more times. Not all numbers are beautiful, but we can make any base 10 positive i...
2019-03-08 17:02:00
106
转载 LeetCode 698 Partition to K Equal Sum Subsets
Problem Description: Given an array of integersnumsand a positive integerk, find whether it's possible to divide this array intoknon-empty subsets whose sums are all equal.输入是一个整型数组和一个正整数...
2019-03-07 18:17:00
131
转载 LeetCode 312. Burst Balloons
Problem Description:Givennballoons, indexed from0ton-1. Each balloon is painted with a number on it represented by arraynums. You are asked to burst all the balloons. If the you burst ba...
2019-03-05 17:08:00
62
转载 leetcode 1001. Grid Illumination
Problem Descriptino:On aN x Ngrid of cells, each cell(x, y)with0 <= x < Nand0 <= y < Nhas a lamp.Initially, some number of lamps are on.lamps[i]tells us the location of...
2019-03-04 15:46:00
107
转载 leetcode 76. Minimum Window Substring 滑动窗口(转)
I will first give the solution then show you the magic template.The code of solving this problem is below. It might be the shortest among all solutions provided in Discuss.string minW...
2018-11-12 15:17:00
106
转载 leetcode 75. Sort Colors
one pass solution.要求一次遍历即完成排序。思路:设置两个指针(zeros和twos)指向数组的头部(-1)和尾部(nums.length)。用索引i遍历整个数组,找到0即放到数组左边,指针zeros向右移动1位;找到2即放在数组右边,twos向左移动1位。注意点:1、i从0遍历到twos,而不是从0遍历到nums.length。因为twos即twos右边...
2018-10-16 21:10:00
83
转载 floyd cycle detection 小总结
到目前为止做了200道leetcode,大多是按照从易到难的顺序,已经三次遇到完全不同的情景,但是采取floyd cycle detection 算法能够有效解决的问题的了。floyd cycle detection 都是采用一快一慢两个指针,快的一次向前移动两步,慢的一次向前移动一步,这样快的每次都会多领先慢的一步。如果有环那么慢和快一定会相遇。第一次是在链表的tag里遇到的:...
2018-05-28 20:47:00
234
转载 防止溢出 LeetCode69.Sqrt(x)
题目描述:Implementint sqrt(int x).Compute and return the square root ofx.xis guaranteed to be a non-negative integer.思路:二分查找,时间复杂度O(logn)。if(mid的平方等于x或者mid的平方小于x且mid+1的平方大于x) return mid;...
2018-04-01 10:33:00
183
转载 LeetCode 35. Search Insert Position
题目描述:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in th...
2017-05-21 15:37:00
79
转载 LeetCode:21MergeTwoSortedList
题目描述:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.出错:访问空指针 member access within null pointer o...
2017-05-14 21:08:00
100
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人