leetcode 数据结构

本次题解包括

  • 20. Valid Parentheses
  • 146 LRU Cache
  • 150 Evaluate Reverse Polish Notation
  • 155 Min Stack
  • 187 Repeated DNA Sequences
  • 208 Implement Trie (Prefix Tree)
  • 211 Add and Search Word – Data structure design
  • 218 The Skyline Problem
  • 232 Implement Queue using Stacks
  • 239 Sliding Window Maximum
  • 341 Flatten Nested List Iterator
  • 352 Data Stream as Disjoint Intervals
  • 432 All O’one Data Structure

Continue reading


kindle paperwhite 笔记按名分类

Cool Idea

kindle 是我最喜欢的设备之一,入手一年以来,在上面我已经阅读了将近70本书,而又喜欢原版的系统(因为可以接受各种推送。如浏览网页直接 推送到kindle上等),刷了多看又卸载掉。kindle的原书笔记很丑。而且按照标记笔记时间进行排列。要是我同时读的有多本,标记的也有多本呢?那笔记会十分混乱。所以决定写下代码,帮助我进行分类。

之前在CSDN写过C++的,版本称为1.0吧,不过有bug就是中文字符什么的。

现在更新pyhon2.0版。

Continue reading


leetcode Text Justification

leetcode Text Justification

Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.

You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces ' ' when necessary so that each line has exactlyL characters.

Extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line do not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right.

For the last line of text, it should be left justified and no extra space is inserted between words.

For example,
words: ["This", "is", "an", "example", "of", "text", "justification."]
L: 16.

Return the formatted lines as:

[
“This is an”,
“example of text”,
“justification. ”
]

Note: Each word is guaranteed not to exceed L in length.

Continue reading


leetcode Simplify Path

leetcode 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 this case, you should return "/".
  • Another corner case is the path might contain multiple slashes '/' together, such as "/home//foo/".
    In this case, you should ignore redundant slashes and return "/home/foo".

Continue reading