当前位置:网站首页>JS absolute minimum value of the sum of Huawei od two numbers
JS absolute minimum value of the sum of Huawei od two numbers
2022-07-25 03:57:00 【Big chicken legs are best】
title : The absolute value of the sum of the two numbers is the smallest | The time limit :1 second | Memory limit :32768K | Language restrictions : There is no limit
Given an ordered sequence of integers from small to large ( There are positive and negative integers ) Array nums , Please find two numbers in the array , The absolute value of its sum (|nums[x]+nums[y]|) Is the minimum , And return this absolute value .
Each input will only correspond to one answer . however , The same element in an array cannot be used twice .
Input description :
Output description :
The absolute minimum of the sum of two numbers
Example 1
Input :
-3 -1 5 7 11 15
Output :
2
explain :
because |nums[0] + nums[2]| = |-3 + 5| = 2 Minimum , So back 2
let nums = readline().split(" ").map(Number);
let n = nums.length;
let min = Infinity
for(let i=0;i<n-1;i++){
for(let j=i+1;j<n;j++){
let count = Math.abs(nums[i] + nums[j]);
min = Math.min(count, min);
}
}
console.log(min);边栏推荐
- "Introduction to interface testing" punch in to learn day04: how to abstract the procedural test script into a test framework?
- Which securities company is better to open an account? Is it safe to open an account on your mobile phone
- Time complexity and space complexity
- Secondary vocational network security skills competition P100 dcore (light CMS system) SQL injection
- Network security - information hiding - use steganography to prevent sensitive data from being stolen
- Traditional architecture of enterprise digital transformation to medium platform micro service architecture
- Sword finger offer II 041. Average value of sliding window_____ Using queue / loop array implementation
- A 20 yuan facial cleanser sold tens of thousands in seven days. How did they do it?
- 基于ABP实现DDD--领域逻辑和应用逻辑
- Li Kou 279 complete square - dynamic programming
猜你喜欢

Bond network card mode setting

Yuntu says digital asset chain: your God of digital asset property protection

Hw2021 attack and defense drill experience - Insights

Pytorch deep learning practice lesson 8 importing data
![[template engine] microservice Learning Notes 6: freemaker](/img/6a/cfe9c5aea0f7fc83d0812237de2256.png)
[template engine] microservice Learning Notes 6: freemaker

Solve "nothing added to commit but untracked files present"“

Fiddler grabs packets and displays err_ TUNNEL_ CONNECTION_ FAILED
![Advanced numbers | [calculus of multivariate function] chain derivation method, implicit function derivation method, total differential form invariance, multivariate function extremum](/img/a8/c18118bb97118ebc4e1af7a08337b4.png)
Advanced numbers | [calculus of multivariate function] chain derivation method, implicit function derivation method, total differential form invariance, multivariate function extremum

EMQ Yingyun technology was successfully selected into the 2022 "cutting edge 100" list of Chinese entrepreneurs

Machine learning exercise 8 - anomaly detection and recommendation system (collaborative filtering)
随机推荐
Implementation of online number or fan query of the scene
[kaggle] how to effectively avoid oom and the long process of alchemy
Message queue (MQ)
[matlab] solve the mex error there was a problem creating the mex file for real time execution, please ensure y
An article takes you quickly to learn flex layout
144. Preorder traversal of binary tree
[Flink] rich function
MySQL eight shares
MIM command
Sales system of infant products based on SSH
Niuke interview high frequency list (group 1) difficulty: simple & medium
Force deduction problem 238. product of arrays other than itself
Imeta | ggclusternet microbial network analysis and visualization nanny level tutorial
Top101 [linked list] must be applied for interview
Moveit2 - 7. Scenario planning ROS API
MySQL
Machine learning exercise 8 - anomaly detection and recommendation system (collaborative filtering)
LeetCode. 302 weekly games___ 03_ 6121. Query the number smaller than k after cutting the number____ sort
[Flink] submit the jar package to the Flink cluster and run it
Implementing DDD based on ABP -- domain logic and application logic