We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 20e3bb8 + b7c2d2f commit 3cddae0Copy full SHA for 3cddae0
2560. House Robber IV
@@ -0,0 +1,34 @@
1
+class Solution {
2
+public:
3
+ bool ispossible(vector<int>& nums, int mid, int k){
4
+ int count_of_houses = 0;
5
+ int i = 0;
6
+ while(i < nums.size()){
7
+ if(nums[i] <= mid){
8
+ count_of_houses ++;
9
+ i += 2;
10
+ }
11
+ else{
12
+ i++;
13
14
15
+ return count_of_houses >= k;
16
17
+
18
+ int minCapability(vector<int>& nums, int k) {
19
+ int left = *min_element(nums.begin(), nums.end());
20
+ int right = *max_element(nums.begin(), nums.end());
21
+ int result = right;
22
+ while(left <= right){
23
+ int mid = left + (right - left)/2;
24
+ if(ispossible(nums, mid, k) == true){
25
+ result = mid;
26
+ right = mid-1;
27
28
29
+ left = mid+1;
30
31
32
+ return result;
33
34
+};
0 commit comments