<> Programming questions 1:

subject : The sum of two numbers in the array is a fixed value
Original title :leetcode1 Two Sum
<https://leetcode.com/problems/two-sum/description/>

Given an array of integers and a target value , Find two numbers in the array and that are the target values
Examples :
given nums = [2, 7, 11, 15], target = 9
because nums[0] + nums[1] = 2 + 7 = 9
So go back [2,7]
function fin(nums,tag) { var re=[]; for(var i=0;i<nums.length;i++){ for(var
j=i+1;j<nums.length;j++){ if(nums[i]+nums[j]==tag){ re[0]=nums[i];
re[1]=nums[j] } } } return re } var nums=[2,7,11,15] var t=9;
console.log(fin(nums,t))
<> Programming questions 2

subject : Stock maximum profit
Original title :leetcode122 Best Time to Buy and Sell Stock II
<https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/description/>

Suppose you have an array , Its first i An element is a given stock in the i Day's price .
If you are only allowed to complete one transaction at most , Design an algorithm to find the maximum profit .
example :
Input: [7,1,5,3,6,4]
Output: 7
Explanation: Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit =
5-1 = 4.
Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.
Input: [7,6,4,3,1]
Output: 0
Explanation: In this case, no transaction is done, i.e. max profit = 0.
function maxProfit(prices) { var sum=0; let len=prices.length; for (let i = 0;
i <= len; i++ ) { if(prices[i]<prices[i+1]){ sum+=prices[i+1]-prices[i]; } }
return sum; }; var arrr=[7,6,5,4,3,2,1] console.log(maxProfit(arrr))