# 2073. Time Needed to Buy Tickets ###### tags: `Leetcode` `Easy` Link: https://leetcode.com/problems/time-needed-to-buy-tickets/description/ ## Code ```java= class Solution { public int timeRequiredToBuy(int[] tickets, int k) { int time = 0; for(int i=0; i<tickets.length; i++){ if(i<=k){ time += Math.min(tickets[i], tickets[k]); } else time += Math.min(tickets[i], tickets[k]-1); } return time; } } ```
×
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