题解 | #最大数#

最大数

http://www.nowcoder.com/practice/fc897457408f4bbe9d3f87588f497729

import java.util.*;


public class Solution {
    /**
     * 最大数
     * @param nums int整型一维数组 
     * @return string字符串
     */
   public static String solve (int[] nums) {
     	//使用Stream流转成Integer数组
       Integer[] nums2 = Arrays.stream(nums).boxed().toArray(Integer[]::new);
     	//定义返回值 默认为空
        String res ="";
        // write code here
     	//自定义排序规则
        Arrays.sort(nums2,new Comparator<Integer>(){
            @Override
            public int compare(Integer a, Integer b) {
                return (""+b + ""+a).compareTo(a +""+ b+"");
            }
        });
     	//如果排序后第一个为空 则表示数组中全是0
        if (nums2[0].equals(0)){
            return "0";
        }
     	//拼接结果
        for (int i = 0; i < nums2.length; i++) {
            res=res+nums2[i];
        }
        return res;
    }
}
全部评论

相关推荐

frutiger:逆天,我家就安阳的,这hr咋能说3k的,你送外卖不比这工资高得多?还说大厂来的6k,打发叫花子的呢?这hr是怎么做到说昧良心的话的
找工作时遇到的神仙HR
点赞 评论 收藏
分享
uu们,拒offer时hr很生气怎么办我哭死
爱睡觉的冰箱哥:人家回收你的offer,或者oc后没给你发offer的时候可不会愧疚你,所以你拒了也没必要愧疚他。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务