Problem 71: Simplify Path
思路
这道题就是把原来的 String split 开,然后再拼接成新的字符串
需要注意的几个 corner cases: (1) Did you consider the case where path = "/../"? In this case, you should return "/". (2) 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".
易错点
equals() 和 ==
equals() 方法比较的是 String 的内容是否相同;而 “==” 比较的是两个 Object 是否是同一个,比的是地址值。
最后去掉末尾的 “/”
Last updated