1 Star 0 Fork 0

amusement1234/LeetCode_Java

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
71.简化路径.java 728 Bytes
Copy Edit Raw Blame History
amusement1234 authored 2021-09-14 13:42 +08:00 . add list
import java.util.Deque;
import java.util.LinkedList;
/*
* @lc app=leetcode.cn id=71 lang=java
*
* [71] 简化路径
*/
// @lc code=start
class Solution {
public String simplifyPath(String path) {
Deque<String> deque = new LinkedList<>();
for (String str : path.split("/")) {
if (str.equals("..")) {
if (!deque.isEmpty()) {
deque.pop();
}
} else if (!str.isEmpty() && !str.equals(".")) {
deque.push(str);
}
}
String res = "";
while (!deque.isEmpty()) {
res = "/" + deque.pop() + res;
}
return res.isEmpty() ? "/" : res;
}
}
// @lc code=end
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/amusement1234/LeetCode_Java.git
git@gitee.com:amusement1234/LeetCode_Java.git
amusement1234
LeetCode_Java
LeetCode_Java
master

Search