Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 87bc969

Browse files
Merge pull request #282 from hellomrsun/master
Add C# solutions
2 parents 980d16a + 04cad79 commit 87bc969

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

‎README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Solutions in various programming languages are provided. Enjoy it.
1616
7. [Word Pattern](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/07-Word-Pattern)
1717
8. [Sum of Root To Leaf Binary Numbers](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/08-Sum-of-Root-To-Leaf-Binary-Numbers)
1818
9. [Compare Version Numbers](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/09-Compare-Version-Numbers)
19+
10. [Bulls and Cows](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/10-Bulls-and-Cows)
20+
11. [Maximum Product Subarray](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/11-Maximum-Product-Subarray)
21+
12. [Combination Sum III](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/12-Combination-Sum-III)
1922

2023
## August LeetCoding Challenge
2124
Click [here](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/) for problem descriptions.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class Solution {
2+
public string GetHint(string secret, string guess) {
3+
var bulls = 0;
4+
var cows = 0;
5+
int[] secretarr = new int[10];
6+
int[] guessarr = new int[10];
7+
for(int i=0; i<secret.Length; i++){
8+
if(secret[i] == guess[i]){
9+
bulls++;
10+
}else {
11+
++secretarr[secret[i] - '0'];
12+
++guessarr[guess[i] - '0'];
13+
}
14+
}
15+
for (int i = 0; i < 10; ++i) {
16+
cows += Math.Min(secretarr[i], guessarr[i]);
17+
}
18+
return bulls + "A" + cows + "B";
19+
}
20+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class Solution {
2+
public int MaxProduct(int[] nums)
3+
{
4+
int s = nums[0];
5+
int r = nums[0];
6+
7+
for(int i=1, max = s, min = s; i<nums.Length; i++){
8+
int temp = max;
9+
max = Math.Max(Math.Max(nums[i] * max, nums[i] * min), nums[i]);
10+
min = Math.Min(Math.Min(nums[i] * temp, nums[i] * min), nums[i]);
11+
12+
r = Math.Max(max, r);
13+
}
14+
15+
return r;
16+
}
17+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
public class Solution {
2+
public IList<IList<int>> CombinationSum3(int k, int n)
3+
{
4+
var res = new List<IList<int>>();
5+
var tmp = new List<int>();
6+
Backtrack(res, tmp, k, n, 1);
7+
return res;
8+
}
9+
10+
public void Backtrack(List<IList<int>> res, List<int> tmp, int k, int n, int idx)
11+
{
12+
if (k == tmp.Count && n == 0)
13+
{
14+
res.Add(new List<int>(tmp)); //Deep clone
15+
return;
16+
}
17+
18+
for (int i = idx; i <= n && k > 0 && n > 0; i++)
19+
{
20+
if(i>9) break;
21+
tmp.Add(i);
22+
Backtrack(res, tmp, k, n - i, i + 1);
23+
tmp.RemoveAt(tmp.Count - 1); //Remove last item when it doesn't find the correct combo
24+
}
25+
}
26+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /