[ 命名建議 ] LeetCode 209. Minimum Size Subarray Sum #115
Answered
by
twy30
LPenny-github
asked this question in
Q&A
-
|
LeetCode: 線上教材: 再麻煩 @twy30 給予命名建議 orz 感激不盡 using System;
namespace Sandbox
{
public class Solution
{
public int MinSubArrayLen(int s, int[] nums)
{
int target = s;
int[] input = nums;
int subarraySum = 0;
int startIndex = 0, endIndex = 0;
int subarrayMinLength = 0;
for (endIndex = 0; endIndex < input.Length; ++endIndex)
{
subarraySum += input[endIndex];
while (subarraySum >= target)
{
if (subarrayMinLength == 0)
{
subarrayMinLength = endIndex - startIndex + 1;
}
else
{
subarrayMinLength = Math.Min(subarrayMinLength, endIndex - startIndex + 1);
}
subarraySum -= input[startIndex];
++startIndex;
}
}
return subarrayMinLength;
}
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
twy30
Jan 17, 2021
Replies: 1 comment 1 reply
-
|
你好 😊 int subarrayMinLength = 0;這裡也可以寫成
其它的變數命名我覺得都 ok 👌 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
LPenny-github
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@LPenny-github
你好 😊
這裡也可以寫成
minSubarrayLength,看個人的語感覺得下列兩者哪個比較順:subarrayMinLength)minSubarrayLength)其它的變數命名我覺得都 ok 👌