当前位置:网站首页>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)
边栏推荐
- Introduction of time related knowledge in kernel
- 五千字讲清楚团队自组织建设 | Liga 妙谈
- How to test MDM products
- 能源行业的数字化“新”运维
- Android uses sqliteopenhelper to flash back
- The controversial line of energy replenishment: will fast charging lead to reunification?
- I always thought that excel and PPT could only be used for making statements until I saw this set of templates (attached)
- What if Kaili can't input Chinese???
- Pytorch深度学习之环境搭建
- TCP两次挥手,你见过吗?那四次握手呢?
猜你喜欢
uni-app与uviewUI实现仿小米商城app(附源码)
Unity makes revolving door, sliding door, cabinet door drawer, click the effect of automatic door opening and closing, and automatically play the sound effect (with editor extension code)
超标量处理器设计 姚永斌 第7章 寄存器重命名 摘录
ISO27001 certification process and 2022 subsidy policy summary
Once the "king of color TV", he sold pork before delisting
With an estimated value of 90billion, the IPO of super chip is coming
How to test MDM products
五千字讲清楚团队自组织建设 | Liga 妙谈
Unity 制作旋转门 推拉门 柜门 抽屉 点击自动开门效果 开关门自动播放音效 (附带编辑器扩展代码)
Recast of recastnavigation
随机推荐
“在越南,钱就像躺在街上”
Detectron2 installation method
Pytoch deep learning environment construction
How to improve development quality
高中物理:力、物体和平衡
Open source PostgreSQL extension age for graph database was announced as the top-level project of Apache Software Foundation
Introduction of time related knowledge in kernel
Face_recognition人脸识别之考勤统计
How to test MDM products
如何使用 wget 和 curl 下载文件
I always thought that excel and PPT could only be used for making statements until I saw this set of templates (attached)
Tutorial on the use of Huawei cloud modelarts (with detailed illustrations)
Easy to use map visualization
【Hot100】32. Longest valid bracket
怎么开户才是安全的,
The block:usdd has strong growth momentum
【210】PHP 定界符的用法
You should know something about ci/cd
2022年全国CMMI认证补贴政策|昌旭咨询
Face_ Attendance statistics of recognition face recognition