feat: 2025-10-30打卡

This commit is contained in:
wu xiangkai
2025-10-30 16:31:25 +08:00
parent b897d019fa
commit 71664a10cc
3 changed files with 135 additions and 0 deletions

34
71.simplify-path.java Normal file
View File

@@ -0,0 +1,34 @@
/*
* @lc app=leetcode id=71 lang=java
*
* [71] Simplify Path
*/
// @lc code=start
class Solution {
public String simplifyPath(String path) {
String[] dirs = path.split("/");
ArrayList<String> stack = new ArrayList<>();
for(String dir: dirs) {
if(dir.isEmpty() || dir.equals(".")) {
continue;
} else if(dir.equals("..")) {
if(!stack.isEmpty()) {
stack.removeLast();
}
} else {
stack.addLast(dir);
}
}
if(stack.isEmpty()) {
return "/";
}
StringBuilder sb = new StringBuilder();
for(String dir: stack) {
sb.append("/").append(dir);
}
return sb.toString();
}
}
// @lc code=end