#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. css构造文本

    1. 1. 文本缩进text-indent:值:值为数字,最常用的数值单位是px(像素),也可以直接是百分比!text-indent:100px;text-indent:10%;2. 文本对齐text ...

  2. A C[HDU1570]

    A C Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  3. c++ map删除元素

    typedef std::map<std::string,float> StringFloatMap; StringFloatMap col1; StringFloatMap::itera ...

  4. 关于sql语句的优化问题

    系统要求进行SQL优化,对效率比较低的SQL进行优化,使其运行效率更高,其中要求对SQL中的部分in/not in修改为exists/not exists 修改方法如下: in的SQL语句 SELEC ...

  5. 简单Qt网络通信

    最近要用到Qt的Socket部分,网上关于这部分的资料都比较复杂,我在这总结一下,把Socket的主要部分提取出来,实现TCP和UDP的简单通信. 1.UDP通信 UDP没有特定的server端和cl ...

  6. 关于isset使用产生Can't use function return value in write context错误

    在使用isset检测session的一个取值是否存在时,产生了这个问题 翻译一下:不能在填写的内容中使用函数的返回值.然后我查看了php手册看isset函数的使用:isset()只能用于变量,因为传递 ...

  7. MUI - 手势

    www.bcty365.com/content-146-2389-1.html 配置事件 mui.init({ gestureConfig: { hold: true, //长按屏幕,默认是false ...

  8. 微博开发平台java SDK demo学习之friendships

    本文解释了在java SDK的demo中与feiendships有关的功能 截图如下: 关注一个用户(需要知道该用户uid) 取消关注一个用户(用户uid) 获取用户粉丝列表(授权用户的screen_ ...

  9. Ubuntu 启动停止脚本

    /etc/init.d 目录下的开机启动脚本 1. more redis_8010 #/bin/sh #Configurations injected by install_server below. ...

  10. HDU 4738 Caocao's Bridges(Tarjan求桥+重边判断)

    Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...