当前位置:网站首页>Leecode brushes questions to record interview questions 17.16 massagist

Leecode brushes questions to record interview questions 17.16 massagist

2022-07-07 00:12:00 Why is there a bug list

List of articles

topic

A famous masseuse will receive a steady stream of appointment requests , Every appointment can be accepted or not . There should be a break between appointments , So she can't accept the next appointment . Given an appointment request sequence , Find the best set of appointments for the masseuse ( The longest total appointment time ), Return the total minutes .

Be careful : This question is slightly changed from the original one

Example 1:

Input : [1,2,3,1]
Output : 4
explain : choice 1 No. and 3 Booking No , Total duration = 1 + 3 = 4.
Example 2:

Input : [2,7,9,3,1]
Output : 12
explain : choice 1 Booking No 、 3 No. and 5 Booking No , Total duration = 2 + 9 + 1 = 12.
Example 3:

Input : [2,1,4,5,3,1,1,3]
Output : 12
explain : choice 1 Booking No 、 3 Booking No 、 5 No. and 8 Booking No , Total duration = 2 + 4 + 3 + 3 = 12.

answer

class Solution {
    
    public int massage(int[] nums) {
    
        int a = 0, b = 0;
        for (int i = 0; i < nums.length; i++) {
    
            int c = Math.max(b, a + nums[i]);
            a = b;
            b = c;
        }
        return b;
    }
}
原网站

版权声明
本文为[Why is there a bug list]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131017365094.html