leetcode Count of Range Sum
Given an integer array
nums
, return the number of range sums that lie in[lower, upper]
inclusive. Range sumS(i, j)
is defined as the sum of the elements innums
between indicesi
andj
(i
≤j
), inclusive.Note: A naive algorithm of O(_n_2) is trivial. You MUST do better than that.
Example: Given nums =
[-2, 5, -1]
, lower =-2
, upper =2
, Return3
. The three ranges are :[0, 0]
,[2, 2]
,[0, 2]
and their respective sums are:-2, -1, 2
.
leetcode Power of Three
leetcode Power of Three
Given an integer, write a function to determine if it is a power of three.
Follow up: Could you do it without using any loop / recursion?
leetcode 274 H-Index || 275 H-Index II
leetcode 274 H-Index
Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.
According to the definition of h-index on Wikipedia: "A scientist has index h if h of his/her N papers have at least h citations each, and the other N − h papers have no more than h citations each."
For example, given
citations = [3, 0, 6, 1, 5]
, which means the researcher has5
papers in total and each of them had received3, 0, 6, 1, 5
citations respectively. Since the researcher has3
papers with at least3
citations each and the remaining two with no more than3
citations each, his h-index is3
.Note: If there are several possible values for
h
, the maximum one is taken as the h-index.Hint:
- An easy approach is to sort the array first.
- What are the possible values of h-index?
- A faster approach is to use extra space.
【十五年最后一别】再见,火影
火影忍者 剧场版 博人传 影评
2015年总结
leetcode Wiggle Sort II
leetcode Wiggle Sort II
Given an unsorted array
nums
, reorder it such thatnums[0] < nums[1] > nums[2] < nums[3]...
.Example: (1) Given
nums = [1, 5, 1, 1, 6, 4]
, one possible answer is[1, 4, 1, 5, 1, 6]
. (2) Givennums = [1, 3, 2, 2, 3, 1]
, one possible answer is[2, 3, 1, 3, 1, 2]
.Note: You may assume all input has valid answer.
Follow Up: Can you do it in O(n) time and/or in-place with O(1) extra space?
leetcode Coin Change
leetcode Coin Change
You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return
-1
.Example 1: coins =
[1, 2, 5]
, amount =11
return3
(11 = 5 + 5 + 1)Example 2: coins =
[2]
, amount =3
return-1
.Note: You may assume that you have an infinite number of each kind of coin.
Github student pack 申请
为什么要申请github student pack呢?
因为身为学生,可以享受如下优惠
- digitalocean vps 50$ (之前貌似是100 ,博主一年VPS不用钱了~)
- 5个github 私有仓库
- 等等
虽然是大四旺,但是,还是在校学生,申请个福利并不是干什么坏事~
leetcode Create Maximum Number
leetcode Create Maximum Number
Given two arrays of length
m
andn
with digits0-9
representing two numbers. Create the maximum number of lengthk <= m + n
from digits of the two. The relative order of the digits from the same array must be preserved. Return an array of thek
digits. You should try to optimize your time and space complexity.Example 1:
nums1 =
[3, 4, 6, 5]
nums2 =[9, 1, 2, 5, 8, 3]
k =5
return[9, 8, 6, 5, 3]
Example 2:
nums1 =
[6, 7]
nums2 =[6, 0, 4]
k =5
return[6, 7, 6, 0, 4]
Example 3:
nums1 =
[3, 9]
nums2 =[8, 9]
k =3
return[9, 8, 9]