1038 Recover the Smallest Number

博客解析了LeetCode的1038题,通过直接按位排序并针对不同长度字符串进行讨论来解决问题。特别注意了测试点2全为0的情况,通过设置标志位来处理开头0的输出问题。
摘要由CSDN通过智能技术生成

1038 Recover the Smallest Number

题目地址

思路:

直接按位排序,对不同长度的字符串分情况讨论(从没写过这么长的cmp函数)

坑:

测试点2 全部都是0;
因为输出最终数字的时候开头的0不输出,所以设立一个标志位检测省略过开头的0没,什么都没输出(全部省略)就再补充一个0

AC代码:

#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

struct number{
	char num[10];
	int len;
	int index;
}a[10010]; 

bool cmp(number a,number b){
	if(a.num[0]!=b.num[0]) return a.num[0]<b.num[0];
	else{
		for(int i=0;i<min(a.len,b.len);i++){
			if(a.num[i]!=b.num[i]){
				return a.num[i]<b.num[i];
			}
		}
		if(a.len<b.len){
			if(b.num[a.len]!=a.num[0]) return a.num[0]<b.num[a.len];
			els
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值