当前位置:网站首页>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;
}边栏推荐
- Exclusive download. Alibaba cloud native brings 10+ technical experts to bring new possibilities of cloud native and cloud future
- QT (x): packaging and deployment
- Share 10 interview questions related to JS promise
- Service grid ASM year end summary: how do end users use the service grid?
- try anbox (by quqi99)
- Hyperledger Fabric 2. X custom smart contract
- [Flink] flinksql and table programming cases
- Qt foreach关键字
- Fault: display Storport driver out of date in component health
- Go basic data types: characters and strings
猜你喜欢

Observer mode vs publish subscribe mode

jetson tx2

Chapter IV introduction to FPGA development platform

层次分析法
![[when OSPF introduces direct connection routes, it makes a summary by using static black hole routes]](/img/a8/f77cc5e43e1885171e73f8ab543ee4.png)
[when OSPF introduces direct connection routes, it makes a summary by using static black hole routes]

json tobean

Why are keys unordered in golang map

How to do the performance pressure test of "Health Code"

Illustrate plug-in -- AI plug-in development -- creative plug-in -- astute graphics -- length and angle measurement function

Two methods for preorder traversal of binary tree
随机推荐
Mongostat performance analysis
关于DDNS
The annual technology inventory of cloud primitives was released, and it was the right time to ride the wind and waves
Baidu applet automatically submits search
QT (x): innosetup for software packaging
idea使用
Servlet version conflict causes page 404
Annual inventory review of Alibaba cloud's observable practices in 2021
Illustrate plug-in -- AI plug-in development -- creative plug-in -- astute graphics -- path width style function
Exclusive download. Alibaba cloud native brings 10+ technical experts to bring new possibilities of cloud native and cloud future
开源二三事|ShardingSphere 与 Database Mesh 之间不得不说的那些事
Some high-level usage of localstorage
How to change the password after forgetting the MySQL password (the latest version of 2022 detailed tutorial nanny level)
P5 DS - component and document Association
Single application and microservice application
关于 localStorage 的一些高阶用法
Error: GPG check FAILED Once install MySQL
百度小程序自动提交搜索
2022.02.15 - SX10-31. House raiding III
Antlr4 recognizes the format of escape string containing quotation marks