#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 1000
int cmp(char *s1,char *s2){
char temp1[];
char temp2[];
strcpy(temp1,s1);
strcat(temp1,s2);
strcpy(temp2,s2);
strcat(temp2,s1);
if(strcmp(temp1,temp2)<)return ;
else return ;
}
char* into_string(int n){
char *p;
p=(char*)malloc(*sizeof(char));
sprintf(p,"%d",n);
return p;
}
char* largestNumber(int* nums, int numsSize) {
char re[][];
char temp[];
char *p;
int i,j;
p=(char*)malloc(MAX*sizeof(char));
for(i=;i<numsSize;i++)strcpy(re[i],into_string(nums[i]));
for(i=;i<numsSize;i++){ //用的冒泡,不好意思@@ 虽然这是这题的核心算法,思想就是判断两个字串要不要交换位置的条件是,将这两个字串分别以两种方式拼接,再比较哪一                  //种拼接更优
for(j=i+;j<numsSize;j++)
if(cmp(re[i],re[j])){
strcpy(temp,re[i]);
strcpy(re[i],re[j]);
strcpy(re[j],temp);
}
}
for(i=,p[]='\0';i<numsSize;i++)
strcat(p,re[i]);
while(*p=='')p++;
if(*p=='\0')return "";
return p;
}

Largest Number || LeetCode的更多相关文章

  1. Largest Number——LeetCode

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  2. [LeetCode] Largest Number 最大组合数

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  3. JavaScript中sort方法的一个坑(leetcode 179. Largest Number)

    在做 Largest Number 这道题之前,我对 sort 方法的用法是非常自信的.我很清楚不传比较因子的排序会根据元素字典序(字符串的UNICODE码位点)来排,如果要根据大小排序,需要传入一个 ...

  4. Leetcode:Largest Number详细题解

    题目 Given a list of non negative integers, arrange them such that they form the largest number. For e ...

  5. [LeetCode][Python]Largest Number

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/largest ...

  6. LeetCode之“排序”:Largest Number

    题目链接 题目要求: Given a list of non negative integers, arrange them such that they form the largest numbe ...

  7. 【Leetcode】179. Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  8. leetcode 179. Largest Number 、剑指offer33 把数组排成最小的数

    这两个题几乎是一样的,只是leetcode的题是排成最大的数,剑指的题是排成最小的 179. Largest Number a.需要将数组的数转换成字符串,然后再根据大小排序,这里使用to_strin ...

  9. [LeetCode] 179. Largest Number 最大组合数

    Given a list of non negative integers, arrange them such that they form the largest number. Example ...

随机推荐

  1. POJ1780 Code(欧拉路径)

    n位密码,要用尽可能短的序列将n位密码的10n种状态的子串都包括,那么要尽量地重合. 题目已经说最短的是10n + n - 1,即每一个状态的后n-1位都和序列中后一个状态的前n-1位重合. 这题是经 ...

  2. BZOJ3103 : Palindromic Equivalence

    用Manacher可以推出O(n)对相等和不等关系. 将相等的用并查集维护,不等的连边. 然后从1到n,如果该等价类还没被考虑过,则ans*=26-与它不等的考虑过的等价类个数. #include&l ...

  3. Ruby Hash与ActiveSupport’s HashWithIndifferentAccess对于key的区别

    Ruby Hash的key定义的时候是支持symbol或者string的,所以访问的时候只能是symbol或者string其中一种方式. 建议使用symbol定义Hash的key,因为symbol在R ...

  4. 用LinqPad查看Nhibernate生成的sql语句

    使用Nhibernate开发一般都要对Nhibernate生成的sql语句进行查看及分析,查看Nhibernate生成的sql语句,可以使用NHProfiler和log4net.但NHProfiler ...

  5. SpringMVC+Spring+MyBatis整合完整版Web实例(附数据)

    最近段时间正在学习Spring MVC和MyBatis的一些知识.自己也在网络上面找了一些例子来练习.但是都不是很完整.所以,今天,自己也抽空写了个完成的关于Spring MVC + Spring + ...

  6. mac 下的 top 命令

    mac 下的 top 命令 文章目录 以前只是在 linux 机器上使用 top 命令.常用的快键键是: p 键 - 按 cpu 使用率排序 m 键 - 按内存使用量排序 这 2 个快捷键在 mac ...

  7. 让input不可编辑的方法

    两种方法: disabled="true " 文字会变成灰色,不可编辑. readOnly="true" 文字不会变色,也是不可编辑的 <input na ...

  8. cmd下常用的一些命令

    1.calc计算器 2.Mspaint画图 3.Netstat -anb查看端口 输入netstat -anb时可能会遇到下面问题 只要到搜索框输入cmd,然后到其快捷方式上右击以管理员身份运行即可 ...

  9. Html - 返回Top

    制作浮动top $(window).scroll( function() { var scrollValue=$(window).scrollTop(); scrollValue > 600 ? ...

  10. CSS系列:less备忘

    less备忘 //这是一个运行在koala中的less文件,//注释不会被编译到css文件中,/**/注释会 ****************by 李可 2016/04/19 /*所有,所有伪类*/ ...