Merged
Conversation
liquo-rice
reviewed
May 8, 2024
| (Nは要素数、Kは文字列の最大文字数) | ||
|
|
||
| #### メモ | ||
| - Hashmapの初期値をListにする方法が出てこなかったため、時間内にPassできず。 |
Owner
Author
There was a problem hiding this comment.
ヒントを頂いたように、以下のようにすでに値が存在しているか確認をして、なければ追加をする(カルテ作る)形になると思いました!
// hash = { 'a': [], 'b': [] }
if 'a' in hash:
hash['a'].append("apple")
else:
hash['a'] = ["apple"]| ans = {} | ||
|
|
||
| for s in strs: | ||
| arr = [0] * 26 |
There was a problem hiding this comment.
26がmagic numberです。定数を定義するといいでしょう。arrという変数名をもっと分かりやすくするならどうしますか?
Owner
Author
There was a problem hiding this comment.
26を定数として定義するといいこと、わかりました!
arrについて、
使用用途が文字列に使用されている文字数のカウントアップなので、char_countsとかが適切であったかと思います。
|
|
||
| #### 調べた解法 | ||
| - Step1と同様にASCII値とListを使用した方法。 | ||
| - ソートされた文字列をkeyとして使用する方法。(NKlogK for time comp, N for space comp) |
Owner
Author
There was a problem hiding this comment.
step-2-1.pyに別解のコーディングも入れてみました!
Owner
Author
|
しばらく空けても解けたのでマージします。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://leetcode.com/problems/group-anagrams/description/
Description
Given an array of strings strs, group the anagrams together. You can return the answer in any order.
An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
Example 1:
Example 2:
Example 3:
Constraints: