[ 命名建議 ] LeetCode 503. Next Greater Element II #118
Answered
by
twy30
LPenny-github
asked this question in
Q&A
-
|
LeetCode: 線上教材: 再麻煩 @twy30 給予命名建議 orz 感激不盡 using System;
using System.Collections.Generic;
public class Solution
{
public int[] NextGreaterElements(int[] nums)
{
int[] inputNumbers = nums;
Stack<int> nextGreaterNumberStack = new Stack<int>();
int[] output = new int[inputNumbers.Length];
Array.Fill(output, -1);
for (int i = 0; i < inputNumbers.Length * 2 ; ++i)
{
int currentIndex = i % inputNumbers.Length;
while (nextGreaterNumberStack.Count > 0 &&
inputNumbers[nextGreaterNumberStack.Peek()] < inputNumbers[currentIndex])
{
output[nextGreaterNumberStack.Pop()] = inputNumbers[currentIndex];
}
nextGreaterNumberStack.Push(currentIndex);
}
return output;
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
twy30
Jan 20, 2021
Replies: 1 comment 1 reply
-
|
你好 😊 int currentIndex = i % inputNumbers.Length;我不覺得
若改成以下名字,也是可以的:
其它的變數名稱我覺得都 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
你好 😊
我不覺得
currentIndex有什麼問題,但因為其使用情景很簡單(simple):若改成以下名字,也是可以的:
inputNumbersIndexindexj其它的變數名稱我覺得都 ok 👌