当前位置:网站首页>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);边栏推荐
- Interview question 08.07. Permutation and combination of non repeated strings DFS method
- word怎么取消退出修订模式
- Force button brushing question 61. rotating linked list
- 144. Preorder traversal of binary tree
- Pytorch deep learning practice lesson 8 importing data
- [file upload] parse text files and store them in batches through JDBC connection (dynamic table creation and dynamic storage)
- High temperature in Britain: two airport runways were burnt out, and several railways were restricted to ensure safety
- Chapter 18 request matcher serverwebexchangematcher of oauth2loginauthenticationwebfilter
- Bond network card mode setting
- [kaggle] how to effectively avoid oom and the long process of alchemy
猜你喜欢

Force deduction brush question 14. Longest common prefix
![[file upload] parse text files and store them in batches through JDBC connection (dynamic table creation and dynamic storage)](/img/9c/0305f7256ab6037d586c8940b9dc76.png)
[file upload] parse text files and store them in batches through JDBC connection (dynamic table creation and dynamic storage)

ECCV 2022 | rethinking image blending for data enhancement in vision transformers
![[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

CVPR 2022 | content aware text logo image generation method

Memory leak due to improper handling of custom view

Servlet个人实操笔记(一)

Use of CCleaner

Analysis of browser working principle

Message queue (MQ)
随机推荐
Memory leak due to improper handling of custom view
Unity: text input box for numerical judgment
DNS resolution experiment
Deep learning method of building a model from zero
Table of contents of force deduction questions
Redis official visualization tool, with high appearance value and powerful functions!
VMware installation
Machine learning notes - building a recommendation system (4) matrix decomposition for collaborative filtering
MySQL
Experience sharing of system architecture designers in preparing for the exam: how to prepare for the exam effectively
Execution flow control of shell
How to cancel and exit revision mode for word
An article takes you quickly to learn flex layout
DNS domain name resolution service
Traditional architecture of enterprise digital transformation to medium platform micro service architecture
Installation and tutorial of MATLAB curling simulation game
Machine learning exercise 8 - anomaly detection and recommendation system (collaborative filtering)
ES(8.1)认证题目
[Flink] submit the jar package to the Flink cluster and run it
EMQ Yingyun technology was successfully selected into the 2022 "cutting edge 100" list of Chinese entrepreneurs