Skip to content

Commit 37297e4

Browse files
add 633
1 parent 015d920 commit 37297e4

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Your ideas/fixes/algorithms are more than welcome!
2020

2121
| # | Title | Solutions | Time | Space | Difficulty | Tag | Notes
2222
|-----|----------------|---------------|---------------|---------------|-------------|--------------|-----
23+
|633|[Sum of Square Numbers](https://leetcode.com/problems/sum-of-square-numbers/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_633.java) | O(logn) |O(1) | Easy | Binary Search
2324
|628|[Maximum Product of Three Numbers](https://leetcode.com/problems/maximum-product-of-three-numbers/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_628.java) | O(nlogn) |O(1) | Easy |
2425
|625|[Minimum Factorization](https://leetcode.com/problems/minimum-factorization/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_625.java) | O(?) |O(?) | Medium |
2526
|624|[Maximum Distance in Arrays](https://leetcode.com/problems/maximum-distance-in-arrays/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_624.java) | O(nlogn) |O(1) | Easy | Sort, Array
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.fishercoder.solutions;
2+
3+
/**
4+
* 629. K Inverse Pairs Array
5+
*
6+
* Given two integers n and k, find how many different arrays consist of numbers from 1 to n such that there are exactly k inverse pairs.
7+
We define an inverse pair as following: For ith and jth element in the array,
8+
if i < j and a[i] > a[j] then it's an inverse pair; Otherwise, it's not.
9+
Since the answer may very large, the answer should be modulo 109 + 7.
10+
11+
Example 1:
12+
Input: n = 3, k = 0
13+
Output: 1
14+
Explanation:
15+
Only the array [1,2,3] which consists of numbers from 1 to 3 has exactly 0 inverse pair.
16+
17+
Example 2:
18+
Input: n = 3, k = 1
19+
Output: 2
20+
Explanation:
21+
The array [1,3,2] and [2,1,3] have exactly 1 inverse pair.
22+
23+
Note:
24+
The integer n is in the range [1, 1000] and k is in the range [0, 1000].
25+
*/
26+
public class _629 {
27+
28+
public int kInversePairs(int n, int k) {
29+
return 0;
30+
}
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.fishercoder.solutions;
2+
3+
/**
4+
* Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c.
5+
6+
Example 1:
7+
Input: 5
8+
Output: True
9+
Explanation: 1 * 1 + 2 * 2 = 5
10+
11+
Example 2:
12+
Input: 3
13+
Output: False
14+
*/
15+
public class _633 {
16+
public boolean judgeSquareSum(int c) {
17+
if (c < 0) return false;
18+
int left = 0;
19+
int right = (int) (Math.sqrt(c));
20+
while (left <= right) {
21+
int curr = left*left + right*right;
22+
if (curr > c) {
23+
right--;
24+
} else if (curr < c) {
25+
left++;
26+
} else {
27+
return true;
28+
}
29+
}
30+
return false;
31+
}
32+
}

0 commit comments

Comments
 (0)