mirror of https://github.com/doocs/leetcode.git
parent
8aea3edb73
commit
705fcd39c8
|
|
@ -1,17 +0,0 @@
|
|||
public class Solution {
|
||||
public int GetWinner(int[] arr, int k) {
|
||||
int maxElement = arr[0], count = 0;
|
||||
for (int i = 1; i < arr.Length; i++) {
|
||||
if (maxElement < arr[i]) {
|
||||
maxElement = arr[i];
|
||||
count = 1;
|
||||
} else {
|
||||
count++;
|
||||
}
|
||||
if (count == k) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return maxElement;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
public class Solution {
|
||||
public int[] AnswerQueries(int[] nums, int[] queries) {
|
||||
int[] result = new int[queries.Length];
|
||||
Array.Sort(nums);
|
||||
for (int i = 0; i < queries.Length; i++) {
|
||||
result[i] = getSubsequent(nums, queries[i]);
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public int getSubsequent(int[] nums,int query) {
|
||||
int sum = 0;
|
||||
for (int i = 0; i < nums.Length; i++) {
|
||||
sum += nums[i];
|
||||
if (sum > query) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return nums.Length;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue