Skip to content

209. Minimum Size Subarray Sum - #43

Open
akmhmgc wants to merge 1 commit into
mainfrom
209
Open

209. Minimum Size Subarray Sum#43
akmhmgc wants to merge 1 commit into
mainfrom
209

Conversation

@akmhmgc

@akmhmgc akmhmgc commented Oct 4, 2025

Copy link
Copy Markdown
Owner

解いた問題

209. Minimum Size Subarray Sum

使用言語

Ruby

次に解く問題

https://leetcode.com/problems/permutations/

@akmhmgc akmhmgc added the ruby label Oct 4, 2025
Comment thread 209/step3.md
# @return {Integer}
def min_sub_array_len(target, nums)
min_size = Float::INFINITY
prefix_sum = 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.

prefix_sum というよりは subarray_sum かなと感じました。

Comment thread 209/step3.md
# @param {Integer[]} nums
# @return {Integer}
def min_sub_array_len(target, nums)
min_size = Float::INFINITY

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

初期値は難しいところですが選択肢の一つとして以下のパターンもありだとは思いました。

NOT_FOUND = nums.size + 1
min_size = NOT_FOUND
...
min_size == NOT_FOUND ? 0 : min_size

Comment thread 209/step3.md
end
prefix_sum += num
end
min_size == Float::INFINITY ? 0 : min_size

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

いいと思います。
別の書き方としては、while trueで二つのポインタを回すような書き方もあると思いました。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Rubyらしいというのもありますが、必ずrightは1ずつ動くのでわざわざ自分で+1する必要もないかな、と思いこの書き方しています。

ただ、ポインタを使った方がsliding windowらしいのでそれもアリかもしれません。
コメントありがとうございます。

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants