Skip to content
Discussion options

You must be logged in to vote

@LPenny-github

你好 😊


            int index = input.Length;
  • index 可以換成 outputIndex
    • outputIndex 初始化為 output.Length - 1
    • do-while 迴圈中,從 --index 改成 index--
  • 雖然 input.Lengthoutput.Length 的值會是一樣的,但我會選使用 output.Length ,語意上比較一致 😊

            int firstIndex = 0, secondIndex = index -1;
                int firstNumberSquare = input[firstIndex]*input[firstIndex];
                int secondNumberSquare = input[secondIndex]*input[secondIndex];

在這個案例中,是從一個「一維陣列」的 頭/尾 、 始/終 兩個方向向中間夾擊,所以可以試試這樣做:

  • first (第一), second (第二) 可以換成 head (頭), tail (尾)
    • 也可以換成 start (始), end (終)
    • 也可以與 outputIndex 呼應,寫成像這樣: headInputIndex, tailInputIndex
  • 類似上一段提到的觀念,我會用 input.Length - 1 來初始化 secondIndex / tailInputIndex

可…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@LPenny-github
Comment options

@twy30
Comment options

twy30 Jan 5, 2021
Maintainer

@LPenny-github
Comment options

@LPenny-github
Comment options

@twy30
Comment options

twy30 Jan 6, 2021
Maintainer

Answer selected by LPenny-github
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants