# Leetcode 495. Teemo Attacking Runtime: 1 ms faster than 100.00% Memory Usage: 41.6 MB less than 48.71% ``` java= /* [2,3,6,8], duration=3 2 3 4 5 6 7 8 9 10 3-2=1 => duration 3-1=2 8-6=2 => duration 3-2=1 => 2+1=3 少三個(4個數*3(duration)=12 12-3=9) */ class Solution { public int findPoisonedDuration(int[] timeSeries, int duration) { int result=0,minus=0; int temp=-1000000000; // 代表陣列中,前一個數 result = timeSeries.length * duration; for(int num : timeSeries){ if((num-temp)<duration ){ minus+=duration-(num-temp); } temp=num; } return result-minus; } } ``` 解題思維: 先用全部幾個數去乘duration,再扣掉重複計算的部分 Time: O(n) ###### tags: `Array`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up