Leetcode#949. Largest Time for Given Digits
Problem
Given an array arr of 4 digits, find the latest 24-hour time that can be made using each digit exactly once.
24-hour times are formatted as "HH:MM", where HH is between 00 and 23, and MM is between 00 and 59. The earliest 24-hour time is 00:00, and the latest is 23:59.
Return the latest 24-hour time in "HH:MM" format. If no valid time can be made, return an empty string.
Example 1:
1 | Input: arr = [1,2,3,4] |
Example 2:
1 | Input: arr = [5,5,5,5] |
Constraints:
arr.length == 40 <= arr[i] <= 9
Solve
暴力解
很醜O(n^4)
但是因為 n最大也是4
所以沒超出時間
1 | class Solution: |
本部落格所有文章除特別聲明外,均採用 CC BY-NC-SA 4.0 許可協議。轉載請註明來自 Imisky!
評論
