8000 Add C# solutions · MetricVoid/Leetcode@77d7b5a · GitHub
[go: up one dir, main page]

Skip to content

Commit 77d7b5a

Browse files
committed
Add C# solutions
1 parent 7500608 commit 77d7b5a

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Solutions in various programming languages are provided. Enjoy it.
2222
13. [Insert Interval](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/13-Insert-Interval)
2323
14. [House Robber](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/14-House-Robber)
2424
15. [Length of Last Word](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/15-Length-of-Last-Word)
25+
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)
26+
17. [Robot Bounded In Circle](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/17-Robot-Bounded-In-Circle)
2527

2628
## August LeetCoding Challenge
2729
Click [here](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/) for problem descriptions.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public class Solution {
2+
public int FindMaximumXOR(int[] nums) {
3+
int max = 0, mask=0;
4+
for(int i=31; i>=0; i--){
5+
mask |= (1 << i);
6+
7+
var hs = new HashSet<int>();
8+
foreach(int num in nums){
9+
hs.Add(num & mask);
10+
}
11+
12+
int tmp = max | (1 << i);
13+
foreach(int prefix in hs){
14+
if(hs.Contains(tmp ^ prefix)){
15+
max = tmp;
16+
break;
17+
}
18+
}
19+
}
20+
return max;
21+
}
22+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class Solution {
2+
public bool IsRobotBounded(string instructions) {
3+
int x = 0;
4+
int y = 0;
5+
var dirs = new int[4][]{new int[]{0,1}, new int[]{1, 0}, new int[]{0,-1}, new int[]{-1,0}};
6+
int d = 0;
7+
8+
foreach(char c in instructions){
9+
if(c == 'L'){
10+
d = (d+3)%4;
11+
}else if(c == 'R'){
12+
d = (d+1)%4;
13+
}else{
14+
x += dirs[d][0];
15+
y += dirs[d][1];
16+
}
17+
}
18+
19+
return x == 0 && y == 0 || d > 0;
20+
}
21+
}

0 commit comments

Comments
 (0)
0