avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • Resume
  • Archives
  • Categories
  • Photos
  • Music



{{ date }}

{{ time }}

avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • 主页
  • Resume
  • Archives
  • Categories
  • Photos
  • Music

2251.The number of flowers during the flowering period

  2024-01-01        
字数统计: 142字   |   阅读时长: 1min

topic:

screenshot2023-09-29 morning12.54.48.png

2251.The number of flowers during the flowering period.md

Thought:

看的answer,The idea is too complicated。Learned a new library,bisect,Two -point search,Can be used to find the insertion position。

bisect_right(a, x): List in orderaMediumx,returnxThe position that should be inserted,This position is located inaThe right side of all the same elements。

bisect_left(a, x): List in orderaMediumx,returnxThe position that should be inserted,This position is located inaAll of the same elements in the left。

We can usebisect_rightHere,usebisect_leftHere。

Code:

1
2
3
4
5
class Solution:
def fullBloomFlowers(self, flowers: List[List[int]], people: List[int]) -> List[int]:
start, end = sorted(a for a, _ in flowers), sorted(b for _, b in flowers)
# Calculate how many starts before the person have-How many end
return [bisect_right(start, p) - bisect_left(end, p) for p in people]
  • Python
  • answer
  • Prefix and
  • Array
  • Hash table
  • Sort
  • Two -point search
  • Orderly collection

扫一扫,分享到微信

微信分享二维码
213.Hiccup II
2490Return ring sentence
目录
  1. 1. topic:
  2. 2. Thought:
  3. 3. Code:

150 篇 | 131.7k
次 | 人
这里自动载入天数这里自动载入时分秒
2022-2025 loong loong | 新南威尔士龙龙号