Uriel's Corner

Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
posts - 0, comments - 50, trackbacks - 0, articles - 594
问[low high]区间内有多少基数,简单数学题,O(1)


 1 #1523
 2 #Runtime: 22 ms (Beats 34.12%)
 3 #Memory: 13.2 MB (Beats 98.78%)
 4 
 5 class Solution(object):
 6     def countOdds(self, low, high):
 7         """
 8         :type low: int
 9         :type high: int
10         :rtype: int
11         """
12         ans = 0
13         if low < high:
14             ans = (high - low + 1) // 2
15         if low % 2 and high % 2:
16             ans += 1
17         return ans

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理