注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
好久没有发帖子啦,最近因为laid off,狂面了好几家。下面先说一个最简单的fintech startup - level的面!!- class Solution {
- public String simplifyPath(String path) {
- List<String> res = new ArrayList<>();
- String[] parts = path.split("/");
- for(String part:parts){
- if(part.equals(".")||part.equals("")){
- continue;
- }
- if(part.equals("..")){
- if(res.size()<1||res.get(res.size()-1).equals("")){
-
- continue;
- }else{
- res.remove(res.size()-1);
- }
- continue;
- }
- res.add(part);
-
- }
- return "/"+String.join("/",res);
- }
- }
复制代码 谢谢老板们的大米!!!!!!! |