Redian新闻
>
大家的485,团员填不填哦?
avatar
大家的485,团员填不填哦?# Immigration - 落地生根
b*d
1
请教一道leetcode的online judge题,题目一直没看懂。
Given an absolute path for a file (Unix-style), simplify it.
For example,
path = "/home/", => "/home"
path = "/a/./b/../../c/", => "/c"
另外还有几个列子:
/home/foo/../bar" -> "/home/bar"
"/home/foo/./.././bar" -> "/home/bar"
"/home/of/foo/../../bar/../../is/./here/." -> "/is/here"
avatar
z*e
2
是不是填了就自找麻烦哦?
avatar
x*1
3
stack.push all strings between // or / end of string
if . don;t push
if .. pop stack top
after all elements are in the stack, pop all elements, concat string from
right to left s = /element + s;
avatar
b*r
4
团员不用填啊

【在 z****e 的大作中提到】
: 是不是填了就自找麻烦哦?
avatar
b*d
5
谢谢楼上的,只是我还没读懂题意,这个simple路径到底是怎么个回事?

【在 x*******1 的大作中提到】
: stack.push all strings between // or / end of string
: if . don;t push
: if .. pop stack top
: after all elements are in the stack, pop all elements, concat string from
: right to left s = /element + s;

avatar
z*e
6
谢谢,填了个党员已经够麻烦的了,担心得很...
不知是不是要被调查呢,咳

【在 b*********r 的大作中提到】
: 团员不用填啊
avatar
x*1
7
remove all unnecessary character like . .. keep the path as simple as /
string/string/string style
avatar
b*r
8
这个没事,我们也填了,没RFE,直接过了

【在 z****e 的大作中提到】
: 谢谢,填了个党员已经够麻烦的了,担心得很...
: 不知是不是要被调查呢,咳

avatar
b*d
9
谢谢。但下面两个例子感觉也不完全符合你给的定义啊,还有其他的规则吗?
"/home/foo/./.././bar" -> "/home/bar"
"/home/of/foo/../../bar/../../is/./here/." -> "/is/here"

【在 x*******1 的大作中提到】
: remove all unnecessary character like . .. keep the path as simple as /
: string/string/string style

avatar
z*e
10
谢谢!希望也和你们一样good luck!

【在 b*********r 的大作中提到】
: 这个没事,我们也填了,没RFE,直接过了
avatar
f*m
11
同问
avatar
S*g
12
超过28岁自动退团,不算团员
avatar
j*w
13
import java.util.LinkedList;
class Ans
{
public static void main(String[] args)
{
System.out.println(args[0]);
String[] dirs = args[0].split("/");
LinkedList path = new LinkedList();

for (String s : dirs)
{
if ( s.equals("") )
{
continue;
}
else if ( s.equals(".") )
{
continue;
}
else if ( s.equals(".."))
{
path.pollLast();
}
else
{
path.add(s);
}
}

StringBuffer sb = new StringBuffer();
for (String p : path )
{
sb.append("/").append(p);
}

System.out.println(sb.toString());

}
}
avatar
f*m
14
能说说思路吗?
avatar
y*1
15
很符合嚒。你应该照着他的算法做一边。

【在 b***d 的大作中提到】
: 谢谢。但下面两个例子感觉也不完全符合你给的定义啊,还有其他的规则吗?
: "/home/foo/./.././bar" -> "/home/bar"
: "/home/of/foo/../../bar/../../is/./here/." -> "/is/here"

avatar
n*w
16
就是这个。类似栈。空串跟一个点可以合并判断。
unix里边,.是本目录, ..是上一级目录。

【在 j**w 的大作中提到】
: import java.util.LinkedList;
: class Ans
: {
: public static void main(String[] args)
: {
: System.out.println(args[0]);
: String[] dirs = args[0].split("/");
: LinkedList path = new LinkedList();
:
: for (String s : dirs)

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。