Open
Conversation
yamashita-ki
commented
Sep 13, 2025
| - 空間計算量:O(n) | ||
| - 「You must write an algorithm that runs in O(n) time.」と記載があったがSortする方法しか思い浮かばず | ||
| - 考慮漏れしエラーになったケース | ||
| - 与えられたnumsが空の場合を考慮できずエラー |
Owner
Author
There was a problem hiding this comment.
submit後に修正して現在は修正済みです
sakzk
reviewed
Sep 15, 2025
| ```java | ||
| class Solution { | ||
| public int longestConsecutive(int[] nums) { | ||
| if(nums.length == 0) return 0; |
There was a problem hiding this comment.
step1とstep2で、if文のスペースがあったりなかったりしていますね。
体裁面ではPythonであればPEP8や、C++ではgoogleのコーディング規約がよく引用されていると思います。
Javaだとhttps://google.github.io/styleguide/javaguide.htmlなどがあるようです。
sakzk
reviewed
Sep 15, 2025
| ```java | ||
| public class Solution { | ||
| public int longestConsecutive(int[] nums) { | ||
| Set<Integer> numSet = new HashSet<>(); |
There was a problem hiding this comment.
numsから重複を取り除いたものへの命名としては、distinctNums, uniqueNums とかもいいかもです。
命名関係はdiscordだと、https://discord.com/channels/1084280443945353267/1230079550923341835/1230201155619913728 に色々とまとめてくださっています。
sakzk
reviewed
Sep 15, 2025
| ## step2 他の回答を見る | ||
| - 感想: | ||
| - 入力値を数直線上に置いたときに、連続値の始まりかどうかの判別は「左隣の数値が存在するかどうか」という観点を持てていなかった | ||
| - 重複する数値はノイズでしかないのでHash Setでもつという観点もなかった |
There was a problem hiding this comment.
問題のバリエーションとして、重複を省かずにカウントする場合も考えてみると面白いかもです。
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/longest-consecutive-sequence/description/