Skip to content

387. First Unique Character In A String#20

Open
Yuto729 wants to merge 1 commit intomainfrom
first-unique-character-in-a-string
Open

387. First Unique Character In A String#20
Yuto729 wants to merge 1 commit intomainfrom
first-unique-character-in-a-string

Conversation

@Yuto729
Copy link
Copy Markdown
Owner

@Yuto729 Yuto729 commented Dec 22, 2025

@Yuto729 Yuto729 changed the title First Unique Character In A String 387. First Unique Character In A String Dec 22, 2025
Repository owner deleted a comment from github-actions bot Dec 22, 2025
if len(index_list) > 1:
continue

if len(index_list) == 0:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらのコメントをご参照ください。
mamo3gr/arai60#6 (comment)

if len(index_list) == 0:
continue

if first_index == -1:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first_index を大きな数で初期化すると、この if 文が不要になり、シンプルになると思います。

if len(index_list) > 1:
continue

if len(index_list) == 0:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaultdictではアクセスされていないkeyがfor文で取り出されることはないので,このif文は常にfalseですね.

first_index = index_list[0]
continue

first_index = min(first_index, index_list[0])
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python3.7以降ではdefaultdictのfor文による取り出しは要素を追加した順番でとり出されるので,初めてlen(index_list) == 1となる要素が来た時点でearly returnできます.
互換性を考えるとこのままでも良いかもしれません.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants