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)));
  }
}
时间: 2024-10-08 17:22:57

Descending Order的相关文章

poj 2100 Graveyard Design

Graveyard Design Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 7357   Accepted: 1816 Case Time Limit: 2000MS Description King George has recently decided that he would like to have a new design for the royal graveyard. The graveyard m

优先队列实现原理分析

原文出处: ziwenxie 优先队列是在实际工程中被广泛应用的一种数据结构,不管是在操作系统的进程调度中,还是在相关的图算法比如Prim算法和Dijkstra算法中,我们都可以看到优先队列的身影,本文我们就来分析一下优先队列的实现原理. 优先队列 以操作系统的进程调度为例,比如我们在使用手机的过程中,手机分配给来电的优先级都会比其它程序高,在这个业务场景中,我们不要求所有元素全部有序,因为我们需要处理的只是当前键值最大的元素(优先级最高的进程).在这种情况下,我们需要实现的只是删除最大的元素(

【函数】02、匿名函数、生成器、高阶函数

一.匿名函数 1.定义 语法格式: lambda args:expression args:以逗号分隔的参数列表 expression:用到args中各参数的表达式 lambda定义的代码必须是合法的表达式,不能出现多条件语句(可使用if的三元表达式)和非表达式,如for和while等 lambda的首要用途是指定短小的回调函数 lambda将返回一个函数而不是将函数赋值给某变量名 In [77]: lambda x: x+1 Out[77]: <function __main__.<lamb

Graveyard Design POJ - 2100

King George has recently decided that he would like to have a new design for the royal graveyard. The graveyard must consist of several sections, each of which must be a square of graves. All sections must have different number of graves. After a con

udacity 机器学习课程 统计字数

"""Count words.""" def count_words(s, n): """Return the n most frequently occuring words in s.""" # TODO: Count the number of occurences of each word in s word = s.split() worddict = {} for item

TreeSet的学习

TreeSet is another popular implementation of Set interface along with HashSet and LinkedHashSet. All these implementations of Set interface are required in different scenarios. If you don’t want any order of elements, then you can use HashSet. If you

Sliding Window Maximum 解答

Question Given an array of n integer with duplicate number, and a moving window(size k), move the window at each iteration from the start of the array, find the maximum number inside the window at each moving. Example For array [1, 2, 7, 7, 8], movin

WCF安全 z

WCF custom authentication using ServiceCredentials The generally accepted way of authenticating a user with WCF is with a User Name and Password with the UserNamePasswordValidator class.  So common that even MSDN has a tutorial, and the MSDN document

systemtap初学者

1.[[email protected] ~]# stap -v -e 'probe vfs.read {printf("read performed\n"); exit()}' Pass 1: parsed user script and 85 library script(s) using 146900virt/23668res/3024shr/21332data kb, in 130usr/40sys/183real ms. Pass 2: analyzed script: 1