Created
January 22, 2020 12:59
-
-
Save AppleCEO/451b3a843d8b0e8d29c883a8a5c00759 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| func solution(_ d:[Int], _ budget:Int) -> Int { | |
| var total = 0 | |
| var count = 0 | |
| for department in d.sorted() { | |
| if department + total <= budget { | |
| count += 1 | |
| total += department | |
| } else { | |
| break | |
| } | |
| } | |
| return count | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment