当前位置:网站首页>Daily question -1317 Converts an integer to the sum of two zero free integers
Daily question -1317 Converts an integer to the sum of two zero free integers
2022-06-11 22:22:00 【Programmed ape without hair loss 2】
subject :
「 Zero free integer 」 Is in the decimal representation It doesn't contain any 0 The positive integer .
Give you an integer n, Please return one A list of two integers [A, B], Satisfy :
A and B Are zero free integers
A + B = n
The problem data ensures that there is at least one effective solution .
If there are multiple effective solutions , You can return any of them .
Example 1:
Input :n = 2
Output :[1,1]
explain :A = 1, B = 1. A + B = n also A and B The decimal representation of does not contain any 0 .
Example 2:
Input :n = 11
Output :[2,9]
Example 3:
Input :n = 10000
Output :[1,9999]
Example 4:
Input :n = 69
Output :[1,68]
Example 5:
Input :n = 1010
Output :[11,999]
Tips :
2 <= n <= 10^4
java Code :
class Solution {
public int[] getNoZeroIntegers(int n) {
int a = n-1;
int b = 1;
while (true) {
if(isValid(a) && isValid(b)) {
return new int[]{a,b};
}
a--;
b++;
}
}
private boolean isValid(int a) {
if(a%10 ==0) {
return false;
}
while (a>0) {
int temp = a%10;
if(temp ==0) {
return false;
}
a/=10;
}
return true;
}
}
边栏推荐
- Superscalar processor design yaoyongbin Chapter 2 cache -- Excerpt from subsection 2.2
- Simple example of logistic regression for machine learning
- Stack栈的实现
- 分类统计字符个数 (15 分)
- win11怎么看电脑显卡信息
- Collection of articles and literatures related to R language (continuously updated)
- Superscalar processor design yaoyongbin Chapter 2 cache -- Excerpt from subsection 2.3
- Tkinter study notes (IV)
- Superscalar processor design yaoyongbin Chapter 2 cache -- Excerpt from subsection 2.4
- A simple example of linear regression in machine learning
猜你喜欢
![[academic related] under the application review system, how difficult is it to study for a doctoral degree in a double first-class university?](/img/cd/e7ffecbee13596f2298ee8c0a5b873.jpg)
[academic related] under the application review system, how difficult is it to study for a doctoral degree in a double first-class university?

Nmap performs analysis of all network segment IP survivals in host detection

206. reverse linked list

C language to achieve eight sorts (2)

Tkinter学习笔记(二)

二叉树的基本操作与题型总结

Explain asynchronous tasks in detail: the task of function calculation triggers de duplication

MySQL事务简介

Internet of things development practice 18 scenario linkage: how does an intelligent light perceive light? (I) (learning notes)

leetcode 中的位运算
随机推荐
C language implements eight sorts (3)
Basic operation of graph (C language)
Is it safe for qiniu business school to send Huatai account? Really?
剑指offer数组题型总结篇
The device is in use when win10 ejects USB
【NodeJs】Electron安装
The college entrance examination is over, and life has just begun. Suggestions from a 10-year veteran in the workplace
One question of the day - delete duplicates of the ordered array
Daily question - Roman numeral to integer
大学三年应该这样过
STM32开发笔记113:ADS1258驱动设计——读取温度值
C language implements eight sorts of sort merge sort
Implementation stack and queue
360 online enterprise security cloud is open to small, medium and micro enterprises for free
Static PVC with CEPH CSI
【数据挖掘时间序列分析】餐厅销量预测
[nodejs] electron installation
Prefabricated dishes in the trillion market have also begun to roll inside. How can brands stand out in the fierce competition?
238. product of arrays other than itself
Top - K problem