Content-Length: 408199 | pFad | http://github.com/AlgoStudyGroup/Leetcode/commit/21832b1f9061417ae2f74a4237916f684b1eda7b

6E Merge pull request #286 from hellomrsun/master · AlgoStudyGroup/Leetcode@21832b1 · GitHub
Skip to content

Commit 21832b1

Browse files
authored
Merge pull request #286 from hellomrsun/master
Add C# solutions
2 parents e9d1b36 + b83f1c2 commit 21832b1

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Solutions in various programming languages are provided. Enjoy it.
2424
15. [Length of Last Word](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/15-Length-of-Last-Word)
2525
16. [Maximum XOR of Two Numbers in an Array](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/16-Maximum-XOR-of-Two-Numbers-in-an-Array)
2626
17. [Robot Bounded In Circle](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/17-Robot-Bounded-In-Circle)
27+
18. [Best Time to Buy and Sell Stock](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/18-Best-Time-to-Buy-and-Sell-Stock)
28+
19. [Sequential Digits](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/19-Sequential-Digits)
2729

2830
## August LeetCoding Challenge
2931
Click [here](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/) for problem descriptions.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class Solution {
2+
public int MaxProfit(int[] prices) {
3+
if(prices == null || prices.Length == 0) return 0;
4+
int min=prices[0],max=0;
5+
for (int i=1;i<prices.Length;i++){
6+
min=Math.Min(min,prices[i]);
7+
max=Math.Max(max,prices[i]-min);
8+
}
9+
return max;
10+
}
11+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class Solution {
2+
public IList<int> SequentialDigits(int low, int high) {
3+
int[] allNums = {12,23,34,45,56,67,78,89,
4+
123,234,345,456,567,678,789,
5+
1234,2345,3456,4567,5678,6789,
6+
12345,23456,34567,45678,56789,
7+
123456,234567,345678,456789,
8+
1234567,2345678,3456789,
9+
12345678,23456789,
10+
123456789};
11+
var res = new List<int>();
12+
int n = allNums.Length;
13+
for (int i = 0; i < n; i++) {
14+
if (allNums[i] < low) continue;
15+
if (allNums[i] > high) break;
16+
res.Add(allNums[i]);
17+
}
18+
return res;
19+
}
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class Solution {
2+
public int CanCompleteCircuit(int[] gas, int[] cost) {
3+
int sumGas = 0, sumCost = 0, tank = 0, pos = 0;
4+
5+
for(int i = 0; i<gas.Length; i++){
6+
sumGas += gas[i];
7+
sumCost += cost[i];
8+
tank += gas[i] - cost[i];
9+
if(tank < 0){
10+
pos = i+1;
11+
tank = 0;
12+
}
13+
}
14+
15+
if(sumGas >= sumCost){
16+
return pos;
17+
}
18+
19+
return -1;
20+
}
21+
}

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/AlgoStudyGroup/Leetcode/commit/21832b1f9061417ae2f74a4237916f684b1eda7b

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy