GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — LeetCode/Hash/1487.Making-File-Names-Unique at master · black128/LeetCode

Expand file tree

/

1487.Making-File-Names-Unique

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
 
 
/

1487.Making-File-Names-Unique

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
1487.Making-File-Names-Unique.cpp
1487.Making-File-Names-Unique.cpp
 
 
Readme.md
Readme.md
 
 

Readme.md

1487.Making-File-Names-Unique

基本的策略是:对于当前的name,我们首先查看name是否以前出现过。如果没出现过,那么就直接加入。同时更新Map[name]=1,表示以后如果有与name相同的文件加入,则需要“至少”加上后缀1.

如果name出现过的话,我们需要查看name(1)是否出现过,再看name(2)是否出现过...以此类推,直到name(k)没有出现过,就以其作为最终的名字。我们需要的数据结构非常简单,就是以name为key建立的一个Hash表,value就是1,2,...(注意不会有零)。当确定新的文件名是name(k)之后,记得要更新Map[name]+=1,以及Map[name(k)]=1。

这种解法虽然依旧把所有的文件名都存入了Map,空间上并没有优势,但是在查找name(i)的时候可以更快速地定位,时间上会有优势。

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.