当前位置:网站首页>Li Kou brush question diary /day5/2022.6.27
Li Kou brush question diary /day5/2022.6.27
2022-07-04 18:23:00 【Bobo toilet cleaning spirit】
Novice Village
Find the maximum value in an array , have access to Math.max() function
First go MDN Check the instructions on the official website
Want to get the maximum value in an array directly
You can use the following expansion methods
var arr = [1, 2, 3];
var max = Math.max(...arr);
Math.max The usage of has been understood
Example
Their thinking :
Integer networks are stored as two-dimensional arrays , share m That's ok n Column , share m A customer ,n Banks .
So let's define a ans, Return maximum assets ans
Traverse m A customer ,m=accounts.length
Define a number money, Used to store the assets of all banks of each customer
Traverse n Banks ,n=accounts[0].length
Add up the assets of each bank ,money+=accounts[i][j];
Then calculate the maximum value of customer assets ,ans=Math.max[ans,money]
class Solution {
public int maximumWealth(int[][] accounts) {
int ans=0;
for(int i=0;i<accounts.length;i++)
{
int money=0;
for(int j=0;j<accounts[0].length;j++)
{
money +=accounts[i][j];
}
ans = Math.max(ans, money);
}
return ans;
}
}
Find the maximum value in the array and find its subscript
subjunctive
var arr = [1, 20, 30, 60, 80, 90, 99, 89, 100];
var max = arr[0]; // Suppose the first number is the largest
int index = 0; // Define a subscript
for (var i = 0; i < arr.length; i++){ // Compare the other numbers in the array with the maximum number we assume , Traverse
if (max < arr[i]){ // Let them compare in turn , If it is larger than our assumed number
max = arr[i]; // Let's give the value of the larger number to max
index = i; // Subscript the larger value to index
}
} final max That's the maximum
console.log(' The maximum value in this array is :'+ max);
console.log(' The subscript of the maximum value in the array is :'+index)
边栏推荐
- 能源行业的数字化“新”运维
- Weima, which is going to be listed, still can't give Baidu confidence
- 要上市的威马,依然给不了百度信心
- Initial experience of domestic database tidb: simple and easy to use, quick to start
- 估值900亿,超级芯片IPO来了
- DB engines database ranking in July 2022: Microsoft SQL Server rose sharply, Oracle fell sharply
- High school physics: force, object and balance
- 如何进行MDM的产品测试
- Face_recognition人脸识别之考勤统计
- LD_LIBRARY_PATH 环境变量设置
猜你喜欢
Superscalar processor design yaoyongbin Chapter 6 instruction decoding excerpt
【Go语言刷题篇】Go完结篇|函数、结构体、接口、错误入门学习
Open source PostgreSQL extension age for graph database was announced as the top-level project of Apache Software Foundation
7 RSA Cryptosystem
爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
“在越南,钱就像躺在街上”
[cloud native] what is the "grid" of service grid?
People in the workplace with a miserable expression
机器学习概念漂移检测方法(Aporia)
估值900亿,超级芯片IPO来了
随机推荐
表情包坑惨职场人
内核中时间相关的知识介绍
Russia arena data releases PostgreSQL based products
通过事件绑定实现动画效果
Self reflection of a small VC after two years of entrepreneurship
mysql5.7安装教程图文详解
【系统分析师之路】第七章 复盘系统设计(结构化开发方法)
[211] go handles the detailed documents of Excel library
How to improve development quality
Why are some online concerts always weird?
2022年全国CMMI认证补贴政策|昌旭咨询
[daily question] 871 Minimum refueling times
The money circle boss, who is richer than Li Ka Shing, has just bought a building in Saudi Arabia
Set the transparent hidden taskbar and full screen display of the form
Talk about seven ways to realize asynchronous programming
7 RSA Cryptosystem
2022年DCMM认证全国各地补贴政策汇总
明星开店,退,退,退
线上MySQL的自增id用尽怎么办?
比李嘉诚还有钱的币圈大佬,刚在沙特买了楼