摘要: 题目Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).The replacement must be in-place, do not allocate extra memory. 阅读全文
posted @ 2014-01-11 21:30 SangS 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 题目Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.For"(()", the longest valid parentheses substring is"()", which has length = 2.Another example is")()())", where the longes 阅读全文
posted @ 2014-01-11 20:57 SangS 阅读(764) 评论(0) 推荐(0) 编辑
摘要: 题目Clone an undirected graph. Each node in the graph contains alabeland a list of itsneighbors.思路1. 这题明说, label 独一无二, 那么就可以使用 hash map 存储元素2. BFS 搜索, 边搜边向 hash map 添加元素3. 在设置标记位上 TLE 了 N 次, 一个元素一旦被假如到 hash map, 就说明该元素已经被访问到了并已被假如到 queue 中, 同时环的问题也被克服了. 我在做的时候, 把环的问题拉出来单独处理, 但标记忘记了4. unordered_map 这种设 阅读全文
posted @ 2014-01-11 16:49 SangS 阅读(1940) 评论(0) 推荐(0) 编辑
摘要: 题目There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas tank and it costscost[i]of gas to travel from stationito its next station (i+1). You begin the journey with an empty tank at one of the gas stations.Return the starting g 阅读全文
posted @ 2014-01-11 15:29 SangS 阅读(2275) 评论(0) 推荐(0) 编辑
摘要: 题目Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.set(key, value)- Set or insert the value if the key is no 阅读全文
posted @ 2014-01-11 14:28 SangS 阅读(503) 评论(0) 推荐(0) 编辑