There are two test cases in OJ: "dir\n(4-space)file.txt" and "dir\n(4-space)(4-space)file.txt". In the first case, the 4-space is considered as a tab, so that the official answer should be 12. In the second case, the first 4-space is considered as a tab and the second 4-space is considered parts of the file name, so that it should return 16.
Here comes a problem. Suggest the input String is "dir\n\tsubdir\n(4-space)(4-space)file.txt".Should I consider the String "dir\n\tsubdir\n\t(4-space)file.txt" or "dir\n\tsubdir\n\t\tfile.txt"? Actually, the funniest part is, the OJ treats it neither of them. OJ will only return the length of "(4-space)(4-space)file.txt", which is 16. That means, if there is a input String "dirrrrrrrrrrrrrrrrrr\n\tsubdir\n(4-space)(4-space)file.txt", it also returns 16.
That is why I think 4-space considered as a TAB is totally confusing. It seems the author only consider "dir\n(4-space)file.txt" and "dir\n(4-space)(4-space)file.txt" those 2 conditions without sub-dir.
I don't think there is any operating system that supports a filename that starts with space. This test case is quite irrelevant.
Yeah I agree as well.
Cause honestly fuck those cases they just create inconsistencies (and a really headachey edge case)
the 4-space is considered as a tab
No it isn't. In
"dir\n(4-space)file.txt", there simply is a file in the root directory, the filename length is 12, so the path length is 12. Has nothing to do with tabs. Apparently you are the one treating space characters as something special.
I don't think there is any operating system that supports a filename that starts with space.
I just tested Windows and Linux, and as I expected, both support it.
@StefanPochmann You're right. Thank you so much. But I don't think I'm the only one who is confused by the 4-space test case. I don't know why such test cases should be added. Still, thanks for your explanation :)
@StefanPochmann I stand corrected. Your explanation helped me understand the problem much better. Thanks.
oooo I understand now, thanks!
@StefanPochmann one more question, for case "dir\n(4-space)file.txt", the filename length is 12, how could you get the conclusion of the path length is also 12, why you ignore "dir"?
which means dir and (4-space)file.txt are at same level
Another example is a\n\tb.txt\na2\n\tb2.txt means
in which a and a2 are at same level and has files b.txt and b2.txt respectively
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.