当前位置:网站首页>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);边栏推荐
- Postgraduate entrance examination experience
- Localization distillation for dense object detection cvpr2022
- Unity: text input box for numerical judgment
- Li Kou 343 integer partition dynamic programming
- Niuke interview high frequency list (group 1) difficulty: simple & medium
- [Flink] transform operator filter
- CVPR 2022 | content aware text logo image generation method
- Interview question 05.06. integer conversion
- Deeply understand the connection state and reliable mechanism of TCP protocol
- P100 MSSQL database penetration test of secondary vocational network security skills competition
猜你喜欢

MySQL select query part 2

C language_ Defining structures and using variables

Force deduction problem 238. product of arrays other than itself

144. Preorder traversal of binary tree

Operations in shell
![[leetcode medium] 34. Find the first and last positions of elements in the sorted array - array double pointer](/img/f0/e572fe077ddd51b9c160e3382b2a07.png)
[leetcode medium] 34. Find the first and last positions of elements in the sorted array - array double pointer

How should enterprise users choose aiops or APM?

Uniapp picker select the effect demo of provinces and cities (finishing)

CVPR 2020 | social stgcnn: pedestrian trajectory prediction based on graph convolution
![[understanding of opportunity-47]: Guiguzi - Chapter 11 - decision makers, moderation, and rational distribution of interests](/img/f1/e95f230e618d4c4b67b2e0a8c8507b.jpg)
[understanding of opportunity-47]: Guiguzi - Chapter 11 - decision makers, moderation, and rational distribution of interests
随机推荐
DNS domain name resolution service
Swagger key configuration items
Niuke interview high frequency list (group 1) difficulty: simple & medium
Tiktok live broadcast brings goods to help the industry go to sea, and Fastdata observation industry boutique salon helps the ecological development
Optimization of MySQL sorting index fields
基于ABP实现DDD--领域逻辑和应用逻辑
Uniapp picker select the effect demo of provinces and cities (finishing)
MySQL eight shares
Operations in shell
Implementing DDD based on ABP -- domain logic and application logic
Use of CCleaner
Message queue (MQ)
Experience sharing of system architecture designers in preparing for the exam: how to prepare for the exam effectively
Unity: test rotation function
Redis official visualization tool, with high appearance value and powerful functions!
场景之在线人数或者粉丝查询实现
Function method encapsulation -- mutual conversion of image types qpixmap, qimage and mat
LeetCode. 302 weekly games___ 03_ 6121. Query the number smaller than k after cutting the number____ sort
Pytorch deep learning practice lesson 8 importing data
Execution flow control of shell