![]() ![]() ![]() Solution 1: Optimal solution, time complexity is O(n), space complexity is O(n), the idea is to use extra space to record 1 ~ n flower troughs, which is the first few days to bloom. Note: The given array will be in the range. ![]() Example 1:Įxplanation: In the second day, the first and the third flower have become blooming. Each number in the array represents the place where the flower will open in that day.įor example, flowers = x means that the unique flower that blooms at day i will be at position x, where i and x will be in the range from 1 to N.Īlso given an integer k, you need to output in which day there exists two flowers in the status of blooming, and also the number of flowers between them is k and these flowers are not blooming. Given an array flowers consists of number from 1 to N. In each day, there will be exactly one flower blooming and it will be in the status of blooming since then. The N flowers will bloom one by one in N days. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |