当前位置:网站首页>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)
边栏推荐
- Win32 API 访问路由的加密网页
- Face_recognition人脸识别之考勤统计
- 同事悄悄告诉我,飞书通知还能这样玩
- "In Vietnam, money is like lying on the street"
- Performance test of Gatling
- With an estimated value of 90billion, the IPO of super chip is coming
- What if Kaili can't input Chinese???
- MySQL常用增删改查操作(CRUD)
- I wrote a learning and practice tutorial for beginners!
- Redis主从复制
猜你喜欢
Grain Mall (I)
Recast of recastnavigation
With the stock price plummeting and the market value shrinking, Naixue launched a virtual stock, which was deeply in dispute
[cloud native] what is the "grid" of service grid?
RecastNavigation 之 Recast
"In Vietnam, money is like lying on the street"
如何进行MDM的产品测试
What if Kaili can't input Chinese???
Mysql5.7 installation tutorial graphic explanation
MVC mode and three-tier architecture
随机推荐
要上市的威马,依然给不了百度信心
Is it safe to download the mobile version of Anxin securities and open an account online
Redis master-slave replication
正则表达式
The top half and bottom half of the interrupt are introduced and the implementation method (tasklet and work queue)
表情包坑惨职场人
mysql5.7安装教程图文详解
【系统分析师之路】第七章 复盘系统设计(结构化开发方法)
Thawte通配符SSL证书提供的类型有哪些
Summary of subsidy policies across the country for dcmm certification in 2022
Mysql5.7 installation tutorial graphic explanation
Unity 制作旋转门 推拉门 柜门 抽屉 点击自动开门效果 开关门自动播放音效 (附带编辑器扩展代码)
Lua emmylua annotation details
[cloud native] what is the "grid" of service grid?
Android uses sqliteopenhelper to flash back
S5PV210芯片I2C适配器驱动分析(i2c-s3c2410.c)
Mathematical analysis_ Notes_ Chapter 7: differential calculus of multivariate functions
Just today, four experts from HSBC gathered to discuss the problems of bank core system transformation, migration and reconstruction
[proteus simulation] printf debugging output example based on VSM serial port
[210] usage of PHP delimiter