using System.Linq;using System.Collections.Generic;publicclassKata{publicstatic IEnumerable<int>ExtraPerfect(int n){return Enumerable.Range(1, n).Where(x => x %2!=0);}}
答案2:
using System.Collections.Generic;publicclassKata{publicstaticint[]ExtraPerfect(int n){
List<int> list =newList<int>();for(int i =0; i <= n; i++){if(i %2!=0)
list.Add(i);}return list.ToArray();}}
答案3:
using System;using System.Linq;publicclassKata{publicstaticint[]ExtraPerfect(int n){return Enumerable.Range(1, n).Where(x => x %2==1).ToArray();}}
答案4:
using System;using System.Collections.Generic;namespace Solution
{publicclassKata{publicstaticint[]ExtraPerfect(int n){int x =1;
List<int> array =newList<int>();while(n +1> x){
array.Add(n - n + x);
x +=2;}return array.ToArray();}}}
答案5:
using System;using System.Linq;publicclassKata{publicstaticint[]ExtraPerfect(int n)=>Enumerable.Range(1,(n+1)/2).Select((i => i *2-1)).ToArray();}
答案6:
using System;using System.Collections.Generic;publicclassKata{publicstaticint[]ExtraPerfect(int n){
List<int> nums =newList<int>();for(int i =1; i <= n; i++){string bin = Convert.ToString(i,2);if(bin[0]=='1'&& bin[bin.Length -1]=='1'){
nums.Add(i);}}return nums.ToArray();}}
答案7:
using System;using System.Linq;publicclassKata{publicstaticint[]ExtraPerfect(int n)=>
Enumerable.Range(1,n).Where(e=>Convert.ToString(e,2).First()=='1'&& Convert.ToString(e,2).Last()=='1').ToArray();}
答案8:
using System;using System.Collections.Generic;publicclassKata{publicstaticint[]ExtraPerfect(int n){string setBit ="1";
List<int> result =newList<int>();for(int i =1; i <= n; i++){string s = Convert.ToString(i,2);if(s.StartsWith(setBit)&& s.EndsWith(setBit)) result.Add(i);}return result.ToArray();}}
答案9:
using System;using System.Linq;publicclassKata{publicstaticint[]ExtraPerfect(int n)=> Enumerable.Range(0, n +1).Where(x => Convert.ToString(x,2)[0]=='1'&& Convert.ToString(x,2)[Convert.ToString(x,2).Length -1]=='1').ToArray();}
答案10:
using System.Collections.Generic;using System.Linq;publicclassKata{publicstaticint[]ExtraPerfect(int n)=>
Enumerable.Range(1, n).Where(e => e %2!=0).ToArray();}