-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Conversation
- 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)という概念を初めて知った. |
There was a problem hiding this comment.
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)): |
There was a problem hiding this comment.
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))
にしたいと思いました
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while-else や for-else もつかえるでしょうか。
There was a problem hiding this comment.
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)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一応、外側のかっこは不要ですね。
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 |
There was a problem hiding this comment.
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
(時々ライブラリーを確認してみましょう。)
No description provided.