Closed twy30 closed 3 years ago
又來麻煩大大,尋求命名建議了 orz 感激不盡 orz
public int IdenticalPairsCount(int[] inputNumbers)
{
int numberOfIdenticalPairs = 0;
for (int index = 0; index < inputNumbers.Length-1; ++index)
{
for (int nextIndex = index+1; nextIndex< inputNumbers.Length; ++nextIndex)
{
if (inputNumbers[index] == inputNumbers[nextIndex] )
{
++numberOfIdenticalPairs;
}
}
}
return numberOfIdenticalPairs;
}
@LPenny-github
堅持「刻意練習」,一定會進步的 💪
int numberOfIdenticalPairs = 0;
這個命名很好懂 👍
另外可能的寫法有 identicalPairCount
, quantityOfIdenticalPairs
等組合。
for (int index = 0; index < inputNumbers.Length-1; ++index)
{
for (int nextIndex = index+1; nextIndex< inputNumbers.Length; ++nextIndex)
這個地方,或許可以用 i
, j
來代替 index
, nextIndex
🤔
我的想法是:
i
, j
(還有 k
) 算是軟體業常用來表達 索引值 變數的名稱i
, j
(抄錄如下) ;有讀過原題目的讀者應該能聯想到
A pair (i,j) is called good if nums[i] == nums[j] and i < j.
不過,當作練習,如果我們就是不想要用 i
, j
, 那麼,要怎麼命名這兩個索引值變數?
我想我會沿用 LeetCode 題目中的用詞 "good pair", 然後寫成
goodPairIndex1
goodPairIndex2
或
goodPairIndexI
goodPairIndexJ
🤔
@twy30 感謝大大的鼓勵和指教 orz
https://leetcode.com/problems/number-of-good-pairs/
請參考「刷 LeetCode 練習命名」 https://github.com/EngTW/English-for-Programmers/issues/69 😊