-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
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
1281. Subtract the Product and Sum of Digits of an Integer #79
Comments
@twy30 大大,再度麻煩你給予命名建議囉 orz 十分感謝。 (Linq 蠻長的,我不確定怎麼排版會比較好看 🤔 傷眼睛的部分,先說聲抱歉 orz) using System;
using System.Linq;
public class Solution {
public int SubtractProductAndSum(int n) {
int input = n;
int[] inputDigitsArray = input.ToString()
.ToCharArray()
.Select(digit => Convert.ToInt32(digit.ToString()))
.ToArray();
int productOfInputDigitsArray = inputDigitsArray.Aggregate(
(result, digit)=> result * digit);
int sumOfInputDigitsArray = inputDigitsArray.Sum();
return productOfInputDigitsArray - sumOfInputDigitsArray;
}
} |
@LPenny-github 不客氣 😊
沒問題 😊 就練習命名來說,我覺得你的排版還好。
int productOfInputDigitsArray = inputDigitsArray.Aggregate( int sumOfInputDigitsArray = inputDigitsArray.Sum(); 這裡可以試試把
以這個案例的情況來說, 如果 除了 反過來說,因為就只有一個 |
@twy30 感謝大大 orz |
@twy30 大大 請問基數跟底數有什麼不一樣? (出現於留言(#79 (comment) )的參考資料) 我查到的資料,多半是說 可通用 😅 <--沒告訴我 不可 通用的狀況 🤔 所以我還是無法辨別,麻煩大大解釋 orz 感激不盡 |
好問題 😊 坦白說,我也不清楚 😅 從語源學的角度來看,
我一下能想到的只有這些 🤔
其它一些 base, radix 的例子
|
題外話 😊 通常我在貼網址連結時會前後都留一個空白,例如以下是你的原文:
GitHub 把後半的 在網址前後各插入一半形空白字元 (見以下例子)
GitHub 就能正確判斷網址連結,自動把
|
@twy30 感謝大大,我會努力學習。 此外,連結( #79 (comment) )已修正,是我太粗心了 orz |
https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/
參考資料
位數
https://en.wikipedia.org/wiki/Numerical_digit#Computation_of_place_values
例如:
底數(radix) 、基數(base)
https://en.wikipedia.org/wiki/Radix
請參考「刷 LeetCode 練習命名」 #69 😊
The text was updated successfully, but these errors were encountered: