You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* This is a great question for it involves a great idea: virtual index
9
-
```C#
10
-
/// <summary>
11
-
/// WiggleSort
12
-
/// </summary>
13
-
publicclassWiggleSortSln
14
-
{
15
-
privatestaticint[] _array;
16
-
17
-
publicint[] WiggleSort(int[] array)
18
-
{
19
-
_array=array;
20
-
intmedian=findKThLargest(_array.Length/2);
21
-
intleft=0, i=0, right=_array.Length-1;
22
-
23
-
while (i<=right)
24
-
{
25
-
if (_array[newIndex(i)] >median)
26
-
{
27
-
//put newIndex(i) at odd index(from 1, 3, to 5, ...)
28
-
swap(newIndex(left++), newIndex(i));
29
-
i++;
30
-
}
31
-
elseif (_array[newIndex(i)] <median)
32
-
{
33
-
//put newIndex(i) at even index(max even index to little .... )
34
-
swap(newIndex(right--), newIndex(i)); //right--, so i relatively toward right 1 step
35
-
}
36
-
else
37
-
{
38
-
i++;
39
-
}
40
-
}
41
-
return_array;
42
-
}
43
-
44
-
privateintnewIndex(intindex)
45
-
{
46
-
return (1+2*index) % (_array.Length|1);
47
-
}
48
-
49
-
privatevoidswap(inti, intj)
50
-
{
51
-
inttmp=_array[i];
52
-
_array[i] =_array[j];
53
-
_array[j] =tmp;
54
-
}
55
-
56
-
//based on quick sort to find the Kth largest in _array
57
-
privateintfindKThLargest(intk)
58
-
{
59
-
intleft=0;
60
-
intright=_array.Length-1;
61
-
while (true)
62
-
{
63
-
intpivotIndex=quickSort(left, right);
64
-
if (k==pivotIndex)
65
-
return_array[pivotIndex];
66
-
elseif (k<pivotIndex)
67
-
right=pivotIndex-1;
68
-
else
69
-
left=pivotIndex+1;
70
-
}
71
-
}
72
-
73
-
privateintquickSort(intlo, inthi)
74
-
{
75
-
intkey=_array[lo];
76
-
while (lo<hi)
77
-
{
78
-
while (lo<hi&&_array[hi] >=key)
79
-
hi--;
80
-
//hi is less than key, hi element moves to lo index
81
-
_array[lo] =_array[hi];
82
-
while (lo<hi&&_array[lo] <key)
83
-
lo++;
84
-
//lo is bigger than key, lo element moves to hi index
85
-
_array[hi] =_array[lo];
86
-
}
87
-
_array[lo] =key;
88
-
returnlo;
89
-
}
90
-
}
91
-
```
92
-
## Bit Mainpulation
93
-
### 342 Power of Four
94
-
*[Github:#342 Power of Four](/BitManipulation/PowOfFourSln.cs)
95
-
*[CSDN:#342 Power of Four](http://blog.csdn.net/daigualu/article/details/72821233)
96
-
---
97
-
98
-
99
-
# About it
1
+
## About it
100
2
Algorithm is tool for exercising our thinking patterns, and we can strengthen the ability to convert mathematical models into code. Whether you are engaged in artificial intelligence, in-depth learning, or advanced software development, no matter what language you use, such as C#,C++,Java,python,etc., and applying the most appropriate algorithm is always the most important point when faced with a specific problem. *Every problem in practice has its own particularity, which makes it not that easier to choose the most appropriate algorithm.* How do we write the algorithm that most efficiently apply to a practical issue? **Yes, LeetCode.** You can write an algorithm until it accepted, and do not rush to do the next question, and learn the solution someone else has submitted, `so you can solve the problem from the ability of solving the problem to that fast and efficient realm`.
101
3
102
4
I create this respository called **leetcode-csharp** because I apply C# language to solve LeetCode and `every day` will update it and also publish it in `CSDN blog`(http://blog.csdn.net/daigualu) my blog column(http://blog.csdn.net/column/details/14761.html) Also, I will put some algorithm ideas that famous scientists have created on [My Wiki for this repository](https://github.com/jackzhenguo/leetcode-csharp/wiki) such as [Flody tortoise and hare](https://github.com/jackzhenguo/leetcode-csharp/wiki/Floyd's-Tortoise-and-Hare) and [KMP](https://github.com/jackzhenguo/leetcode-csharp/wiki/KMP-getNext) and so on.
103
5
104
6
Anyway, welcome to view, star and fork, then contribute.
105
7
8
+
---
9
+
106
10
## Contributing
107
11
1. Fork it!
108
12
2. Create your feature branch: git checkout -b my-leetcode-csharp
109
13
3. Commit your changes: git commit -am 'Add some questions and better solutions'
110
14
4. Push to the branch: git push origin my-leetcode-csharp
111
15
5. Submit a pull request and enjoy! :D
112
16
17
+
---
18
+
19
+
## Today Update
20
+
[Leetcode Today Update](/TodayUpdate.md)
21
+
113
22
## Solution List
114
23
solutions using C# for leetcode according to tags of questions
0 commit comments