Friday, March 20, 2015

问一道Facebook近期电面题

http://www.mitbbs.com/article_t/JobHunting/32913437.html

发信人: tourist (tourist), 信区: JobHunting
标  题: 问一道Facebook近期电面题
发信站: BBS 未名空间站 (Fri Mar 20 01:45:32 2015, 美东)

Given a string with parentheses, return a string with balanced parentheses
by removing the fewest characters possible. You cannot add anything to the
string.
Examples:
balance("()") -> "()"
balance(")(") -> "".
balance("(((((") -> ""
balance("(()()(") -> "()()"
balance(")(())(") -> "(())"
注意:balance(")(())(") != "()()"

这题看上去比较像LeetCode的Longest Valid Parentheses,求大神们指教只用一个
stack怎么做?

No comments:

Post a Comment