当前位置:网站首页>1317. 将整数转换为两个无零整数的和
1317. 将整数转换为两个无零整数的和
2022-06-27 05:40:00 【Mr Gao】
1317. 将整数转换为两个无零整数的和
「无零整数」是十进制表示中 不含任何 0 的正整数。
给你一个整数 n,请你返回一个 由两个整数组成的列表 [A, B],满足:
A 和 B 都是无零整数
A + B = n
题目数据保证至少有一个有效的解决方案。
如果存在多个有效解决方案,你可以返回其中任意一个。
示例 1:
输入:n = 2
输出:[1,1]
解释:A = 1, B = 1. A + B = n 并且 A 和 B 的十进制表示形式都不包含任何 0 。
示例 2:
输入:n = 11
输出:[2,9]
示例 3:
输入:n = 10000
输出:[1,9999]
示例 4:
输入:n = 69
输出:[1,68]
示例 5:
输入:n = 1010
输出:[11,999]
这题相比较之下比较简单,解题代码如下:
/** * Note: The returned array must be malloced, assume caller calls free(). */
bool f(int n){
while(n){
if(n%10==0){
return false;
}
n=n/10;
}
return true;
}
int* getNoZeroIntegers(int n, int* returnSize){
int *re=(int *)malloc(sizeof(int)*2);
int i;
for(i=1;i<n;i++){
if(f(n-i)&&f(i)){
re[0]=i;
re[1]=n-i;
*(returnSize)=2;
return re;
}
}
return re;
}
边栏推荐
- QListWidgetItem上附加widget
- stm32单片机引脚_如何将单片机的引脚配置为上拉输入
- 躲避小行星游戏
- How pychart installs packages
- Edge loads web pages in IE mode - edge sets ie compatibility
- Chapter 1 Introduction
- Py2neo basic syntax
- STM32关闭PWM输出时,让IO输出固定高或低电平的方法。
- Unicast, multicast and broadcast of IP network communication
- EasyExcel合并相同内容单元格及动态标题功能的实现
猜你喜欢

思维的技术:如何破解工作生活中的两难冲突?

函数栈帧的形成与释放

LeetCode-515. Find the maximum value in each tree row

Nlp-d62-nlp competition d31 & question brushing D15

Tri rapide (non récursif) et tri de fusion

什么是BFC?有什么用?

快速排序(非遞歸)和歸並排序

流媒体协议初探(MPEG2-TS、RTSP、RTP、RTCP、SDP、RTMP、HLS、HDS、HSS、MPEG-DASH)

STM32 reads IO high and low level status

Formation and release of function stack frame
随机推荐
EasyExcel合并相同内容单元格及动态标题功能的实现
函数栈帧的形成与释放
Go日志-Uber开源库zap使用
Py2neo basic syntax
neo4j数据库导出
C语言实现定时器
Asp.Net Core6 WebSocket 简单案例
DAST 黑盒漏洞扫描器 第六篇:运营篇(终)
RTP 发送PS流工具(已经开源)
导航【机器学习】
Ad22 Gerber files Click to open the Gerber step interface. Official solutions to problems
论文解读(LG2AR)《Learning Graph Augmentations to Learn Graph Representations》
jq怎么获取元素的id名
Pytest框架的执行规则
Using domain name forwarding mqtt protocol, pit avoidance Guide
Some articles about component packaging and my experience
Discussion on streaming media protocol (MPEG2-TS, RTSP, RTP, RTCP, SDP, RTMP, HLS, HDS, HSS, mpeg-dash)
QListWidgetItem上附加widget
牛客练习赛101-C 推理小丑---位运算+思维
洛谷P2939 [USACO09FEB]Revamping Trails G 题解