8000 2 · hitzzc/go-leetcode@ffda9a6 · GitHub
[go: up one dir, main page]

Skip to content

Commit ffda9a6

Browse files
committed
2
1 parent a5fc56b commit ffda9a6

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ Golang solution for leetcode. For each problem, there is a simple *_test.go to t
259259
#### [374. Guess Number Higher or Lower](https://github.com/hitzzc/go-leetcode/tree/master/guess_number_higher_or_lower)
260260
#### [375. Guess Number Higher or Lower II](https://github.com/hitzzc/go-leetcode/tree/master/guess_number_higher_or_lower_II)
261261
#### [376. Wiggle Subsequence](https://github.com/hitzzc/go-leetcode/tree/master/wiggle_subsequence)
262+
#### [377. Combination Sum IV](https://github.com/hitzzc/go-leetcode/tree/master/combination_sum_IV)
263+
#### [378. Kth Smallest Element in a Sorted Matrix](https://github.com/hitzzc/go-leetcode/tree/master/kth_smallest_element_in_a_sorted_matrix)
262264

263265

264266

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
int combinationSum4(vector<int>& nums, int target) {
4+
vector<int> dp(target+1, 0);
5+
dp[0] = 1;
6+
for (int i = 1; i <= target; ++i) {
7+
for (auto& num: nums) {
8+
if (num <= i) {
9+
dp[i] += dp[i-num];
10+
}
11+
}
12+
}
13+
return dp[target];
14+
}
15+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
int kthSmallest(vector<vector<int>>& matrix, int k) {
4+
int left = matrix[0][0], right = matrix.back().back();
5+
while (left < right) {
6+
int mid = left + (right - left)/2;
7+
int cnt = 0;
8+
for (auto& vec: matrix) {
9+
cnt += upper_bound(vec.begin(), vec.end(), mid) - vec.begin();
10+
}
11+
if (cnt < k) left = mid + 1;
12+
else right = mid;
13+
}
14+
return left;
15+
}
16+
};

0 commit comments

Comments
 (0)
0