We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/
using System.Linq; public class Solution { public int[] SmallerNumbersThanCurrent(int[] nums) { // 「輸入的數字」(複數) var inputNumbers = nums; // 「最大的可能的『輸入的數字』」 const int maxPossibleInputNumber = 100; // 「『輸入的數字』的數量」(複數) var inputNumberCounts = new int[maxPossibleInputNumber + 1]; foreach (var i in inputNumbers) { ++inputNumberCounts[i]; } // 「 smaller Number 的數量」(複數) var smallerNumberCounts = new int[maxPossibleInputNumber + 1]; for (int i = 1; i < smallerNumberCounts.Length; ++i) { smallerNumberCounts[i] = smallerNumberCounts[i - 1] + inputNumberCounts[i - 1]; } return inputNumbers .Select(number => smallerNumberCounts[number]) .ToArray(); } }
請參考「刷 LeetCode 練習命名」 #69 😊
The text was updated successfully, but these errors were encountered:
@twy30 大大我又來了! 麻煩有空給予命名建議 orz。感激不盡!
using System.Linq; public class Solution { public int[] SmallerNumbersThanCurrent(int[] nums) { // output = 升冪排列好的 input 位置索引 // (若 input 裡有相同的數字,就取最靠近 [0] 的位置索引) // input = [8,1,2,2,3] // 升冪排列 input = [1,2,2,3,8] // index = [0,1,2,3,4] // output = [4,0,1,1,3] int[] inputNumbers = nums; int[] sortedNumbers = new int[inputNumbers.Length]; Array.Copy(inputNumbers, sortedNumbers, inputNumbers.Length); Array.Sort(sortedNumbers); return inputNumbers.Select(digit=>Array.IndexOf(sortedNumbers, digit)).ToArray(); } }
Sorry, something went wrong.
@LPenny-github 歡迎 😊
int[] sortedNumbers = new int[inputNumbers.Length];
另一個可能性是 sortedInputNumbers 。
sortedInputNumbers
以下與命名沒有直接關係 😊
int[] sortedNumbers = new int[inputNumbers.Length]; Array.Copy(inputNumbers, sortedNumbers, inputNumbers.Length);
可以參考 Array.Clone() ( https://docs.microsoft.com/en-us/dotnet/api/system.array.clone?view=net-5.0 )
Array.Clone()
感謝 @twy30 大大指導 orz
Successfully merging a pull request may close this issue.
https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/
請參考「刷 LeetCode 練習命名」 #69 😊
The text was updated successfully, but these errors were encountered: