Movatterモバイル変換


[0]ホーム

URL:


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

Commit9f4e15c

Browse files
authored
Merge pull request#288 from hellomrsun/master
Add C# solutions
2 parents7e24e8b +1243c6f commit9f4e15c

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
publicclassRecentCounter{
2+
3+
privateQueue<int>queue;
4+
privateintcount;
5+
publicRecentCounter(){
6+
count=0;
7+
queue=newQueue<int>();
8+
}
9+
10+
publicintPing(intt){
11+
queue.Enqueue(t);
12+
while(t-queue.FirstOrDefault()>3000)
13+
{
14+
queue.Dequeue();
15+
}
16+
returnqueue.Count();
17+
}
18+
}
19+
20+
/**
21+
* Your RecentCounter object will be instantiated and called as such:
22+
* RecentCounter obj = new RecentCounter();
23+
* int param_1 = obj.Ping(t);
24+
*/

‎README.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
https://leetcode.com
44

5+
6+
##October LeetCoding Challenge
7+
Click[here](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/) for problem descriptions.
8+
9+
Solutions in various programming languages are provided. Enjoy it.
10+
11+
1.[Number of Recent Calls](https://github.com/AlgoStudyGroup/Leetcode/tree/master/October-LeetCoding-Challenge/01-Number-of-Recent-Calls) : Queue
12+
13+
514
##September LeetCoding Challenge
615
Click[here](https://leetcode.com/explore/challenge/card/september-leetcoding-challenge) for problem descriptions.
716

@@ -28,6 +37,7 @@ Solutions in various programming languages are provided. Enjoy it.
2837
19.[Sequential Digits](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/19-Sequential-Digits)
2938
23.[Gas Station](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/23-Gas-Station)
3039
28.[Subarray Product Less Than K](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/28-Subarray-Product-Less-Than-K)
40+
30.[First Missing Positive](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/30-First-Missing-Positive)
3141

3242
##August LeetCoding Challenge
3343
Click[here](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/) for problem descriptions.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
publicclassSolution{
2+
publicintFirstMissingPositive(int[]nums){
3+
intn=nums.Length;
4+
5+
// 1. mark numbers (num < 0) and (num > n) with a special marker number (n+1)
6+
// (we can ignore those because if all number are > n then we'll simply return 1)
7+
for(inti=0;i<n;i++)
8+
{
9+
if(nums[i]<=0||nums[i]>n)
10+
{
11+
nums[i]=n+1;
12+
}
13+
}
14+
// note: all number in the array are now positive, and on the range 1..n+1
15+
16+
// 2. mark each cell appearing in the array, by converting the index for that number to negative
17+
for(inti=0;i<n;i++)
18+
{
19+
intnum=Math.Abs(nums[i]);
20+
if(num>n)
21+
{
22+
continue;
23+
}
24+
num--;// -1 for zero index based array (so the number 1 will be at pos 0)
25+
if(nums[num]>0)
26+
{// prevents double negative operations
27+
nums[num]=-1*nums[num];
28+
}
29+
}
30+
31+
// 3. find the first cell which isn't negative (doesn't appear in the array)
32+
for(inti=0;i<n;i++)
33+
{
34+
if(nums[i]>=0)
35+
{
36+
returni+1;
37+
}
38+
}
39+
40+
// 4. no positive numbers were found, which means the array contains all numbers 1..n
41+
returnn+1;
42+
}
43+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp