123
返回列表 发新帖
楼主: PurpleKing
跳转到指定楼层
上一主题 下一主题
收起左侧

狗家 店面

🔗
wantage3 2021-6-19 15:32:18 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
Falldawn 2021-6-19 23:21:58 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
wantage3 2021-6-20 04:25:51 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
Falldawn 2021-6-20 04:41:55 | 只看该作者
全局:
wantage3 发表于 2021-6-20 04:25
dir121虽然是folder,但是和file.txt一个level的,同一个level里不要求特定顺序的情况下我觉得没有问题。 ...

那如果这样,我直接先对输入排序就然后用stack的方法就可以了
回复

使用道具 举报

🔗
cxw111 2021-6-21 14:23:09 | 只看该作者
全局:
  1. class Node:    def __init__(self):
  2.         self.children = {}
  3.         self.isFile = False # Check if the node is dir or file.


  4. class Trie:
  5.     def __init__(self):
  6.         self._root = Node()

  7.     def insertFile(self, filePath):
  8.         # /a/b -> ['', a, b, c]
  9.         files = filePath.split("/")  # start with 1 for this case.
  10.         if len(files) > 1:
  11.             files = files[1:]
  12.         insertFile = False
  13.         if '.' in files[-1]:
  14.             insertFile = True

  15.         curr = self._root
  16.         for file in files:
  17.             if file not in curr.children:
  18.                 curr.children[file] = Node()
  19.             curr = curr.children[file]
  20.         if insertFile:
  21.             curr.isFile = True

  22.     def printRecursively(self, node: Node, levels: int) -> None:
  23.         for file in node.children:
  24.             # If we want to print by some order, we could get the key of the map, sort it
  25.             # and then do the dfs.
  26.             print('-' * levels + file)
  27.             self.printRecursively(node.children[file], levels + 1)

  28.     def print(self):
  29.         return self.printRecursively(self._root, 1)


  30. trie = Trie()
  31. for file in ["/dir1/dir11/abc.txt", "/dir1/dir12/picture.jpeg", "/dir1/dir12/file1.txt", "/dir3/file2.gif",
  32.              "file3.html", "/dir1/dir12/dir121"]:
  33.     trie.insertFile(file)
  34. trie.print()
复制代码


output:
-dir1
--dir11
---abc.txt
--dir12
---picture.jpeg
---file1.txt
---dir121
-dir3
--file2.gif
-file3.html


回复

使用道具 举报

🔗
hfpt2020 2021-7-14 01:19:09 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
hfpt2020 2021-7-14 01:22:05 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表