Combinations
Given two integers $n$ and $k$, return all possible combinations of $k$ numbers out of 1 … $n$.
For example:
If n = 4 and k = 2, a solution is:1
2
3
4
5
6
7
8[
[2,4],
[3,4],
[2,3],
[1,2],
[1,3],
[1,4],
]
1 | /** |
Compare Version Numbers
Compare two version numbers version1 and version2.
If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0.
You may assume that the version strings are non-empty and contain only digits and the .
character.
The .
character does not represent a decimal point and is used to separate number sequences.
For instance, 2.5
is not “two and a half” or “half way to version three”, it is the fifth second-level revision of the second first-level revision.
Here is an example of version numbers ordering:
0.1 < 1.1 < 1.2 < 13.37
1 | /** |
Complex Number Multiplication
Given two strings representing two complex numbers.
You need to return a string representing their multiplication. Note $i^2 = -1$ according to the definition.
Example 1:1
2
3Input: "1+1i", "1+1i"
Output: "0+2i"
Explanation: (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i, and you need convert it to the form of 0+2i.
Example 2:1
2
3Input: "1+-1i", "1+-1i"
Output: "0+-2i"
Explanation: (1 - i) * (1 - i) = 1 + i2 - 2 * i = -2i, and you need convert it to the form of 0+-2i.
Note
- The input strings will not have extra blank.
- The input strings will be given in the form of a+bi, where the integer a and b will both belong to the range of [-100, 100]. And the output should be also in this form.
1 | class Solution(object): |