当前位置:网站首页>Daily question - force deduction - multiply the found value by 2
Daily question - force deduction - multiply the found value by 2
2022-06-29 06:53:00 【Huige who loves programming】
The title comes from Li Kou ——2154. Multiply the found value by 2 - Power button (LeetCode) (leetcode-cn.com)
Give you an array of integers nums , I'll give you another integer original , This is needed in nums The first number in the search .
Next , You need to follow the steps below :
If in nums Find original , take original multiply 2 , Get new original( namely , Make original = 2 * original).
otherwise , Stop this process .
As long as you can find new in the array original , Right new original continue repeat This process .
return original Of Final value .
Example 1:
Input :nums = [5,3,6,1,12], original = 3
Output :24
explain :
- 3 Can be in nums Find .3 * 2 = 6 .
- 6 Can be in nums Find .6 * 2 = 12 .
- 12 Can be in nums Find .12 * 2 = 24 .
- 24 Can't be in nums Find . therefore , return 24 .
Example 2:Input :nums = [2,7,9], original = 4
Output :4
explain :
- 4 Can't be in nums Find . therefore , return 4 .
int findFinalValue(int* nums, int numsSize, int original){
int i = 0;
int j = 0;
for(j=0;j<numsSize;j++)
{
for(i=0;i<numsSize;i++)
{
if(nums[i] == original)
{
original*=2;
}
}
}
return original;
}边栏推荐
- Hyperledger Fabric 2. X custom smart contract
- Qt 容器类
- Creating a new generation of production and service tools with robot education
- Go basic data type conversion
- QT (x): control operation
- 力扣每日一题-第30天-1523.位1的个数
- Vite quick start
- Annual inventory review of Alibaba cloud's observable practices in 2021
- Why should enterprises do more application activities?
- Analysis comp122 the Caesar cipher
猜你喜欢

RedisTemplate处理hash整数类型的问题解析

Draw multiple ROC curves on a graph

RPC和RMI

Are there too many programmers in China at present?

Browser local storage

Idea use

Exclusive download. Alibaba cloud native brings 10+ technical experts to bring new possibilities of cloud native and cloud future

Chapter IV introduction to FPGA development platform

How does schedulerx help users solve distributed task scheduling problems?

Open source 23 things shardingsphere and database mesh have to say
随机推荐
Design and practice of kubernetes cluster and application monitoring scheme
作为一名合格的网工,你必须掌握的 DHCP Snooping 知识!
Json对象和Json字符串的区别
2022.02.14 - 239. A single element in an ordered array
2022.02.15 - 240. Lucky number in matrix
Fault: display Storport driver out of date in component health
Principle of screen printing adjustment of EDA (cadence and AD) software
Unity AR Shadow 阴影
try anbox (by quqi99)
Annual inventory review of Alibaba cloud's observable practices in 2021
[Flink] flinksql and table programming cases
Exclusive download. Alibaba cloud native brings 10+ technical experts to bring new possibilities of cloud native and cloud future
String and variable are spliced into variable name
UVM authentication platform
List集合实现分页
Qt QFrame详解
Overlay histogram with density curve
Analysis on the wave of learning robot education for children
Teach you how to develop your own NPM package (publish to the NPM official website)
package. Are you familiar with all configuration items and their usage of JSON