Skip to content

387. First Unique Character in a String #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

rinost081
Copy link
Owner

No description provided.

- c++での実装、ただ眺めていた

- https://github.com/mura0086/arai60/pull/19/files#diff-5ec7c3c87171edf4d61e9eb79fd926cafa27caf068da7474222897c8e9e7ab96
- [lru_cache](https://docs.python.org/ja/3.13/library/functools.html#functools.lru_cache)(Least Recently Used cache)という概念を初めて知った.
Copy link

@nktr-cp nktr-cp May 21, 2025

Choose a reason for hiding this comment

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

LRUはOSのページングシステム,CPUやディスクのキャッシュの勉強をしていてもみかけるアルゴリズムだと思うので,覚えておいてもいいかもしれないです

continue
j = i + 1
is_repeat = False
while(j < len(s)):
Copy link

Choose a reason for hiding this comment

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

このwhileはfor j in range(i + 1, len(s))にしたいと思いました

Copy link
Owner Author

Choose a reason for hiding this comment

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

そうですね, なぞにfor文とwhile文が混ざっていますね. 統一するように意識したいと思います

is_repeat = True
j += 1

if is_repeat is False:

Choose a reason for hiding this comment

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

while-else や for-else もつかえるでしょうか。

Copy link
Owner Author

Choose a reason for hiding this comment

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

その発想は持っていませんでした、 確かに使えますね. ありがとうございます

continue
j = i + 1
is_repeat = False
while(j < len(s)):

Choose a reason for hiding this comment

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

一応、外側のかっこは不要ですね。

Comment on lines +12 to +20
j = i + 1
is_repeat = False
while(j < len(s)):
if s[j] == s[i]:
is_repeat = True
j += 1

if is_repeat is False:
return i
Copy link

Choose a reason for hiding this comment

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

ここの部分、find に start をつけたものと同じではないでしょうか。
https://docs.python.org/3/library/stdtypes.html#str.find
(時々ライブラリーを確認してみましょう。)

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.

4 participants