Descending Order

Descending Order

Description:

Your task is to make a function that can take any non-negative integer as a argument and return it with it's digits in descending order. Descending order means that you take the highest digit and place the next highest digit immediately after it.

Examples:

Input: 145263 Output: 654321

Input: 1254859723 Output: 9875543221

using System;
using System.Linq; public static class Kata
{
public static int DescendingOrder(int num)
{
// Bust a move right here
return Convert.ToInt32(string.Join(string.Empty, num.ToString().OrderBy(c => c).Reverse()));
}
}

其他人的解法:值得学习的是,str本身自带了降序排列的函数

关于string.Join以及string.Concat的区别http://www.cnblogs.com/chucklu/p/4621996.html

using System;
using System.Linq; public static class Kata
{
public static int DescendingOrder(int num)
{
return int.Parse(string.Concat(num.ToString().OrderByDescending(x => x)));
}
}
上一篇:messages.exe病毒的清理


下一篇:吴恩达深度学习第1课第3周编程作业记录(2分类1隐层nn)