
leetcode
文章平均质量分 70
liyunlong41
你必须非常努力,才能看起来毫不费力。
展开
-
leetcode84: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 ea...原创 2018-10-21 16:09:34 · 190 阅读 · 0 评论 -
leetcode85:Maximal Rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. Example: Input: [ ["1","0","1","0","0"], ["1","0","1&quo原创 2018-10-21 16:58:03 · 259 阅读 · 0 评论 -
leetcode. Longest Common Prefix最长公共前缀
题目地址:https://leetcode.com/problems/longest-common-prefix/ 需要找到给定字符串数组中所有字符串的最长公共前缀,开始想的是用min个map来存储这些字符串,min是数组中最短字符串的长度,map的key是字符,value是字符出现的次数。 遍历数组中的每个字符串,将每个字符添加到对应的map中,如字符串中第i个字符,添加到第i个map中。最...原创 2018-12-29 18:23:18 · 210 阅读 · 0 评论 -
golang去除排序数组中的重复值 leetcode. Remove Duplicates from Sorted Array
题目地址:https://leetcode.com/problems/remove-duplicates-from-sorted-array/ 去除排好序数组中的重复元素,这里利用一个index j来确定每个不重复元素“应该在的位置”,遍历整个数组,当这个元素与前一个元素相等时,那么j不移动,表明下一个不重复元素应该在这里。当前元素与前一个元素不相同时,当前元素移动到j的位置,j++。 具体的...原创 2018-12-29 18:32:05 · 1081 阅读 · 0 评论 -
leetcode128. Longest Consecutive Sequence 最长连续序列 并查集
题目地址:https://leetcode.com/problems/longest-consecutive-sequence/ 方法1:并查集 这个题的难点在于当更新了某个val后,不能及时更新val周围连续的数值,如val+1, val+2, val-1, val-2等。这里采用并查集的思想,将每一段连续的数值,看做是一个集合,每个集合中有一个leader或者parent。当val值有更新...原创 2019-01-02 20:28:31 · 512 阅读 · 0 评论