#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. Converting Stream to String and back…what are we missing?

    string test = "Testing 1-2-3"; // convert string to stream byte[] byteArray = Encoding.ASC ...

  2. HttpClient_HttpClient 4.3.6 HTTP状态管理

    HTTP状态管理 最初的HTTP被设计成以状态.请求/应答为导向的协议,它被制作成是没有特殊条款的,以便在状态会话中能交换逻辑关系请求/应答.HTTP协议越来越受欢迎和被采用,越来越多的系统会在应用程 ...

  3. MyEclipse10整合Axis2插件

    1.下载axis2的eclipse插件 2.把下载好的两个插件包解压后放置myeclipse10安装目录下的dropins文件夹中 3.重启MyEclipse10后 File->New-> ...

  4. rbegin 和 end 区别

    在使用C++的STL时,经常会用到迭代器,那么不得不搞清楚里面的一些指针 begin(), end(), rbegin(), rend()之间的区别与联系,以及它们分别都指向哪个元素.首先要明白的一点 ...

  5. Solve Error Debug Assertion Failed Expression vector iterators incompatible Using PCL in Release Mode of VS2010

    When using PCL 1.4.0 in the release mode building under VS2010, we might sometime get the error &quo ...

  6. android开发事件监听

    第一种:匿名内部类作为事件监听器类 大部分时候,事件处理器都没有什么利用价值(可利用代码通常都被抽象成了业务逻辑方法),因此大部分事件监听器只是临时使用一次,所以使用匿名内部类形式的事件监听器更合适, ...

  7. 用Editplus开发HTML

    准备工作 设置Editplus默认的打开浏览器为系统默认浏览器 取消Editplus的临时缓存文件 ☆ 设置不生成临时文件 这里的临时文件,指的是.bak文件,当你在Editplus下修改任意一个文件 ...

  8. 漫谈Java虚拟机(JVM)

    Java 虚拟机(JVM)是可运行 Java 代码的假想计算机. 只要根据 JVM 规范描述将解释器移植到特定的计算机上,就能保证经过编译的任何 Java 代码能够在该系统上运行. 从上图中不难明白J ...

  9. 移动Web应用开发入门指南——交互篇

    交互篇 从PC到移动端,视觉和交互是用户能直接感受到的差异.在视觉篇中已经提到,移动设备的物理属性一部分影响到视觉,另外一些部分将影响到交互.那么,移动设备影响交互的物理属性都有哪些变化呢?对于这个问 ...

  10. 2016.04.28,英语,《Vocabulary Builder》Unit 20

    nom, comes from the Latin word for 'name'. nominee is 'named', [ˌnɑːmɪ'niː] n. 被提名的人, 名义人. binomial ...