leetcode 558 设计内存文件系统

本文介绍了如何设计一个内存文件系统,实现ls、mkdir、addContentToFile和readContentFromFile等功能。ls命令根据路径返回文件或目录内容,mkdir创建中间路径不存在的文件夹,addContentToFile追加内容到文件,readContentFromFile读取文件内容。解决方案包括自定义类和哈希表解法。
摘要由CSDN通过智能技术生成

题目

Design an in-memory file system to simulate the following functions:

ls: Given a path in string format. If it is a file path, return a list that only contains this file's name.

If it is a directory path, return the list of file and directory namesin this directory. Your output (file and directory names together) should inlexicographic order.

mkdir: Given adirectory paththat does not exist, you should make a new directory according to the path.

If the middle directories in the path don't exist either, you should create them as well. This function has void return type.

addContentToFile: Given afile pathandfile contentin string format. If the file doesn't exist, you need to create that file containing given content.

If the file already exists, you need toappendgiven content to original content. This function has void return type.

readContentFromFile: Given afile path, return itscontentin string format.

设计一个内存文件系统,模拟以下功能:

ls:以字符串的格式输入一个路径。

如果它是一个文件的路径,那么函数返回一个列表,仅包含这个文件的名字。

如果它是一个文件夹的的路径,那么返回该 文件夹内 的所有文件和子文件夹的名字。

你的返回结果(包括文件和子文件夹)应该按字典序排列。

mkdir:输入一个当前不存在的 文件夹路径 ,你需要根据路径名创建一个新的文件夹。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿啄debugIT

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值