Skip to content

Commit f131452

Browse files
committed
1118
1 parent 4bcea22 commit f131452

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Feel free to submit pull requests, add issues and be a contributer.
2727
|---------------- |---------------- | ----------- | --------------- | --------------- | ------------- |-----|
2828
| Careercup | [Permutation Casewise](https://www.careercup.com/question?id=6255535581036544) | [Java](./java/PermuteCasewise.java) | _O(2^n)_ | _O(1)_ | Medium | |
2929
| Leetcode | [50. Pow(x, n)](https://leetcode.com/problems/powx-n/description/) | [Java](./java/myPow.java) | _O(n)_ | _O(1)_ | Medium | |
30+
| Leetcode | [89. Gray Code](https://leetcode.com/problems/gray-code/description/) | [Java](./java/grayCode.java) | _O(n)_ | _O(1)_ | Medium | |
3031
| Leetcode | [137. Single Number II](https://leetcode.com/problems/single-number-ii/description/) | [Java](./java/singleNumberii.java) | _O(n)_ | _O(1)_ | Medium | |
3132
| Leetcode | [190. Reverse Bits](https://leetcode.com/problems/reverse-bits/description/) | [Java](./java/reverseBits.java) | _O(n)_ | _O(n)_ | Easy | |
3233
| Leetcode | [191. Number of 1 Bits](https://leetcode.com/problems/number-of-1-bits/description/) | [Java](./java/hammingWeight.java) | _O(n)_ | _O(1)_ | Easy | |
@@ -53,6 +54,7 @@ Feel free to submit pull requests, add issues and be a contributer.
5354
| Leetcode | [121. Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/) | [Java](./java/maxProfit.java) | _O(n)_ | _O(1)_ | Easy | |
5455
| Leetcode | [189. Rotate Array](https://leetcode.com/problems/rotate-array/description/) | [Java](./java/rotate.java) | _O(n)_ | _O(1)_ | Easy | |
5556
| Leetcode | [217. Contains Duplicate](https://leetcode.com/problems/contains-duplicate/description/) | [Java](./java/containsDuplicate.java) | _O(n)_ | _O(1)_ | Easy | |
57+
| Leetcode | [228. Summary Ranges](https://leetcode.com/problems/summary-ranges/description/) | [Java](./java/summaryRanges.java) | _O(n)_ | _O(1)_ | Medium | |
5658
| Leetcode | [311. Sparse Matrix Multiplication](https://leetcode.com/problems/sparse-matrix-multiplication/description/) | [Java](./java/sparseMultiply.java) | _O(m*n*l)_ | _O(m*l)_ | Medium | |
5759
| Leetcode | [350. Intersection of Two Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii/description/) | [Java](./java/intersect.java) | _O(m+n)_ | _O(1)_ | Easy | |
5860
| Leetcode | [383. Ransom Note](https://leetcode.com/problems/ransom-note/description/) | [Java](./java/canConstruct.java) | _O(n)_ | _O(1)_ | Easy | |
@@ -249,6 +251,7 @@ Feel free to submit pull requests, add issues and be a contributer.
249251
| Leetcode | [75. Sort Colors](https://leetcode.com/problems/sort-colors/description/) | [Java](./java/sortColors.java) | _O(n)_ | _O(1)_ | Medium | |
250252
| Leetcode | [147. Insertion Sort List](https://leetcode.com/problems/insertion-sort-list/description/) | [Java](./java/insertionSortList.java) | _O(nlogn)_ | _O(1)_ | Medium | |
251253
| Leetcode | [179. Largest Number](https://leetcode.com/problems/largest-number/description/) | [Java](./java/largestNumber.java) | _O(nlogn)_ | _O(n)_ | Medium | |
254+
| Leetcode | [280. Wiggle Sort](https://leetcode.com/problems/wiggle-sort/description/) | [Java](./java/wiggleSort.java) | _O(n)_ | _O(1)_ | Medium | |
252255

253256
## Math
254257
| Website | Title | Solution | Time | Space | Difficulty | Note|

java/grayCode.java

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution {
2+
public List<Integer> grayCode(int n) {
3+
List<Integer> result = new ArrayList<>();
4+
for(int i=0; i < 1<<n; i++)
5+
result.add(i^i>>1);
6+
return result;
7+
}
8+
}

java/summaryRanges.java

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public List<String> summaryRanges(int[] nums) {
3+
List<String> result = new ArrayList<>();
4+
5+
for(int i=0; i<nums.length; i++)
6+
{
7+
int cur = nums[i];
8+
while(i < nums.length-1 && nums[i]+1 == nums[i+1])
9+
i++;
10+
if(cur != nums[i])
11+
result.add(cur + "->" + nums[i]);
12+
else
13+
result.add(cur+"");
14+
}
15+
16+
return result;
17+
}
18+
}

java/wiggleSort.java

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public void wiggleSort(int[] nums) {
3+
for(int i=0; i<nums.length; i++)
4+
{
5+
if(i%2 == 1)
6+
{
7+
if(nums[i] < nums[i-1])
8+
swap(nums, i);
9+
}
10+
else if(i != 0 && nums[i] > nums[i-1])
11+
swap(nums, i);
12+
}
13+
}
14+
15+
public void swap(int [] nums, int k)
16+
{
17+
int temp = nums[k];
18+
nums[k] = nums[k-1];
19+
nums[k-1] = temp;
20+
}
21+
}

0 commit comments

Comments
 (0)