using System.Linq;publicclass solution
{
publicboolvalidate(string n){
return n.Select( c =>(int)char.GetNumericValue(c)).Where( x => x !=-1).Reverse().Select((x, i)=>( i %2==1)?2* x : x ).Select( x =>( x >9)? x -9: x ).Sum()%10==0;}}
答案2:
using System.Linq;publicclass solution
{
publicboolvalidate(string n){
int sum =0;var digits = n.Where(char.IsDigit).Reverse().ToArray();for(int i =0; i < digits.Length; i++){
int term =(int)char.GetNumericValue(digits[i]);if(i %2==1){
term *=2;if(term >9){
term -=9;}}
sum += term;}return sum %10==0;}}
答案3:
using System.Linq;publicclass solution
{
publicboolvalidate(string n)=> n.Replace(" ","").Select(x =>char.GetNumericValue(x)).Reverse().Select((x, i)=> i %2==1? x *2: x).Select(x => x >9? x -9: x).Sum()%10
验证信用卡号【难度:2级】:答案1:using System.Linq;public class solution{ public bool validate(string n) { return n.Select( c => (int) char.GetNumericValue(c) ) .Where( x => x != -1) ...