Skip to content

Create 209. Minimum Size Subarray Sum.md#49

Open
tokuhirat wants to merge 1 commit intomainfrom
209.-Minimum-Size-Subarray-Sum
Open

Create 209. Minimum Size Subarray Sum.md#49
tokuhirat wants to merge 1 commit intomainfrom
209.-Minimum-Size-Subarray-Sum

Conversation

@tokuhirat
Copy link
Owner

This Problem
209. Minimum Size Subarray Sum
Next Ploblem
46. Permutations
言語: Python

if math.isinf(min_length):
return 0
return min_length
```

Choose a reason for hiding this comment

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

特に問題ないと思います。
min_lengthの初期値を何にするかが悩ましいですよね。個人的には、len(nums)+1 だと、intである、min_lenとしてあり得ないことが分かる、想定の最大min_lenより大きくなった場合も対応できるといった観点でいいのかなと思いました。

Copy link
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます。len(nums)+1はいいですね。最後の比較するところがmin_length == len(nums)+1 だとわかりにくい気がしていて、以下のような感じかなと思っています。

NOT_FOUND = len(nums) + 1
min_length = NOT_FOUND
...
if min_length == NOT_FOUND:
    return 0
return min_length

Copy link

@ryosuketc ryosuketc left a comment

Choose a reason for hiding this comment

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

LGTM です

total -= nums[left]
left += 1

if math.isinf(min_length):

Choose a reason for hiding this comment

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

Nit: isinf-inf にも True を返しますね

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.

3 participants