
栈
PKU_CXK
北京大学信息科学技术学院
展开
-
发型糟糕的一天(简单的单调栈运用)
提供两种解法,比较类似 一种是从后向前维护单调递增栈; 另一种是从前向后维护单调递减栈.描述农夫John 的N(1 ≤ N ≤ 80,000)只奶牛中,有一些也许正在经历发型糟糕的一天。每只奶牛对自己乱糟糟的发型都有自知之明,农夫John想知道所有奶牛能看到其他奶牛头顶的数量之和。任意奶牛i身高记为 hi (1 ≤ hi ≤ 1,000,000,000),所有奶牛面向东方(本题示意图的右面)依原创 2016-12-09 17:06:56 · 1154 阅读 · 0 评论 -
LeetCode | 17. Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below. Input:Digit string "23"原创 2017-04-17 15:05:26 · 336 阅读 · 0 评论 -
LeetCode | 20. Valid Parentheses
Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the correct order, “()” and “()[]{}” are all valid but “原创 2017-04-24 20:36:41 · 332 阅读 · 0 评论 -
LeetCode | 56. Merge Intervals——合并区间
Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].思路:按照start排序,然后遍历全部元素,如果完全错开就放进去,如果没有完全错开就修改上一区间的end值。用vector原创 2017-07-02 17:24:20 · 472 阅读 · 0 评论 -
LeetCode | 71. Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"Corner Cases:Did you consider the case where path = "/../"?In thi原创 2017-08-03 01:39:33 · 382 阅读 · 0 评论