Skip to content

Commit

Permalink
feat: add csharp solution to lc problem: No.2389 (doocs#1895)
Browse files Browse the repository at this point in the history

---------

Co-authored-by: Jahir509 <[email protected]>
Co-authored-by: Libin YANG <[email protected]>
  • Loading branch information
3 people authored Oct 29, 2023
1 parent a27055d commit fd17349
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,33 @@ impl Solution {
}
```

### **C#**

```cs
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;
}
}
```

### **...**

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,33 @@ impl Solution {
}
```

### **C#**

```cs
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;
}
}
```

### **...**

```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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;
}
}

0 comments on commit fd17349

Please sign in to comment.