当前位置:网站首页>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)
边栏推荐
- Is BigDecimal safe to calculate the amount? Look at these five pits~~
- TCP两次挥手,你见过吗?那四次握手呢?
- Imitation of numpy 2
- Win32 API 访问路由的加密网页
- 【系统分析师之路】第七章 复盘系统设计(结构化开发方法)
- Is it science or metaphysics to rename a listed company?
- Detectron2 installation method
- Introduction of time related knowledge in kernel
- Superscalar processor design yaoyongbin Chapter 7 register rename excerpt
- 如何提高开发质量
猜你喜欢
Self reflection of a small VC after two years of entrepreneurship
Blue bridge: sympodial plant
如何提高开发质量
Talk about seven ways to realize asynchronous programming
华为云ModelArts的使用教程(附详细图解)
上市公司改名,科学还是玄学?
"In Vietnam, money is like lying on the street"
90后开始攒钱植发,又一个IPO来了
How to improve development quality
Mathematical analysis_ Notes_ Chapter 7: differential calculus of multivariate functions
随机推荐
庆贺!科蓝SUNDB与中创软件完成七大产品的兼容性适配
正则表达式
S5PV210芯片I2C适配器驱动分析(i2c-s3c2410.c)
曾经的“彩电大王”,退市前卖猪肉
内核中时间相关的知识介绍
regular expression
Tutorial on the use of Huawei cloud modelarts (with detailed illustrations)
LD_ LIBRARY_ Path environment variable setting
Self reflection of a small VC after two years of entrepreneurship
What if Kaili can't input Chinese???
The block:usdd has strong growth momentum
People in the workplace with a miserable expression
【Hot100】32. Longest valid bracket
Flask lightweight web framework
78 year old professor Huake impacts the IPO, and Fengnian capital is expected to reap dozens of times the return
[HCIA continuous update] network management and operation and maintenance
Implementation of shell script replacement function
ISO27001认证办理流程及2022年补贴政策汇总
【每日一题】556. 下一个更大元素 III
【Proteus仿真】基于VSM 串口printf调试输出示例