Skip to content

Commit 71a23e0

Browse files
committed
Merge branch 'main' into nc-refactor
2 parents 77d60ff + 230f2c9 commit 71a23e0

4 files changed

+84
-2
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ If you would like to have collaborator permissions on the repo to merge your own
6565
<sub>[2001 - Number of Pairs of Interchangeable Rectangles](https://leetcode.com/problems/number-of-pairs-of-interchangeable-rectangles/)</sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub>
6666
<sub>[2002 - Maximum Product of The Length of Two Palindromic Subsequences](https://leetcode.com/problems/maximum-product-of-the-length-of-two-palindromic-subsequences/)</sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub>
6767
<sub>[2017 - Grid Game](https://leetcode.com/problems/grid-game/)</sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>[✔️](python%2F2017-Grid-Game.py)</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub>
68-
<sub>[438 - Find All Anagrams In a String](https://leetcode.com/problems/find-all-anagrams-in-a-string/)</sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>[✔️](cpp%2F438-Find-All-Anagrams-In-A-String.cpp)</div></sub> | <sub><div align='center'>[✔️](csharp%2F438-Find-All-Anagrams-In-A-String.cs)</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'></div></sub> | <sub><div align='center'>[✔️](python%2F438-Find-All-Anagrams-In-A-String.py)</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub>
68+
<sub>[438 - Find All Anagrams In a String](https://leetcode.com/problems/find-all-anagrams-in-a-string/)</sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>[✔️](cpp%2F438-Find-All-Anagrams-In-A-String.cpp)</div></sub> | <sub><div align='center'>[✔️](csharp%2F438-Find-All-Anagrams-In-A-String.cs)</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>[✔️](kotlin%2F438-Find-All-Anagrams-In-A-String.kt)</div></sub> | <sub><div align='center'>[✔️](python%2F438-Find-All-Anagrams-In-A-String.py)</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub>
6969
<sub>[28 - Find The Index of The First Occurrence In a String](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string/)</sub> | <sub><div align='center'>[✔️](c%2F283-Move-Zeroes.c)</div></sub> | <sub><div align='center'>[✔️](cpp%2F283-Move-Zeroes.cpp)</div></sub> | <sub><div align='center'>[✔️](csharp%2F286-Walls-and-Gates.cs)</div></sub> | <sub><div align='center'>[✔️](go%2F287-Find-the-Duplicate-Number.go)</div></sub> | <sub><div align='center'>[✔️](java%2F286-Walls-and-Gates.java)</div></sub> | <sub><div align='center'>[✔️](javascript%2F283-Move-Zeroes.js)</div></sub> | <sub><div align='center'>[✔️](kotlin%2F287-Find-The-Duplicate-Number.kt)</div></sub> | <sub><div align='center'>[✔️](python%2F28-Implement-strStr.py)</div></sub> | <sub><div align='center'>[✔️](ruby%2F287-Find-The-Duplicate-Number.rb)</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>[✔️](swift%2F287-Find-The-Duplicate-Number.swift)</div></sub> | <sub><div align='center'>[✔️](typescript%2F287-Find-the-Duplicate-Number.ts)</div></sub>
7070
<sub>[280 - Wiggle Sort](https://leetcode.com/problems/wiggle-sort/)</sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub>
7171
<sub>[179 - Largest Number](https://leetcode.com/problems/largest-number/)</sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>[✔️](typescript%2F179-Largest-Number.ts)</div></sub>
@@ -403,7 +403,7 @@ If you would like to have collaborator permissions on the repo to merge your own
403403
<sub>[13 - Roman to Integer](https://leetcode.com/problems/roman-to-integer/)</sub> | <sub><div align='center'>[✔️](c%2F130-Surrounded-Regions.c)</div></sub> | <sub><div align='center'>[✔️](cpp%2F130-Surrounded-Regions.cpp)</div></sub> | <sub><div align='center'>[✔️](csharp%2F130-Surrounded-Regions.cs)</div></sub> | <sub><div align='center'>[✔️](go%2F13-Roman-To-Integer.go)</div></sub> | <sub><div align='center'>[✔️](java%2F130-Surrounded-Regions.java)</div></sub> | <sub><div align='center'>[✔️](javascript%2F13-Roman-to-Integer.js)</div></sub> | <sub><div align='center'>[✔️](kotlin%2F130-Surrounded-Regions.kt)</div></sub> | <sub><div align='center'>[✔️](python%2F13-Roman-To-Integer.py)</div></sub> | <sub><div align='center'>[✔️](ruby%2F133-Clone-Graph.rb)</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>[✔️](swift%2F130-Surrounded-Regions.swift)</div></sub> | <sub><div align='center'>[✔️](typescript%2F130-Surrounded-Regions.ts)</div></sub>
404404
<sub>[12 - Integer to Roman](https://leetcode.com/problems/integer-to-roman/)</sub> | <sub><div align='center'>[✔️](c%2F121-Best-Time-To-Buy-And-Sell-Stock.c)</div></sub> | <sub><div align='center'>[✔️](cpp%2F120-Triangle.cpp)</div></sub> | <sub><div align='center'>[✔️](csharp%2F121-Best-Time-To-Buy-and-Sell-Stock.cs)</div></sub> | <sub><div align='center'>[✔️](go%2F121-Best-Time-To-Buy-And-Sell-Stock.go)</div></sub> | <sub><div align='center'>[✔️](java%2F120-Triangle.java)</div></sub> | <sub><div align='center'>[✔️](javascript%2F1209-Remove-All-Adjacent-Duplicates-in-String-II.js)</div></sub> | <sub><div align='center'>[✔️](kotlin%2F121-Best-Time-to-Buy-and-Sell-Stocks.kt)</div></sub> | <sub><div align='center'>[✔️](python%2F12-Integer-To-Roman.py)</div></sub> | <sub><div align='center'>[✔️](ruby%2F121-Best-Time-To-Buy-and-Sell-Stock.rb)</div></sub> | <sub><div align='center'>[✔️](rust%2F121-Best-Time-To-Buy.rs)</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>[✔️](swift%2F121-Best-Time-To-Buy-And-Sell-Stock.swift)</div></sub> | <sub><div align='center'>[✔️](typescript%2F121-Best-Time-To-Buy-and-Sell-Stock.ts)</div></sub>
405405
<sub>[50 - Pow(x, n)](https://leetcode.com/problems/powx-n/)</sub> | <sub><div align='center'>[✔️](c%2F50-Pow-X-N.c)</div></sub> | <sub><div align='center'>[✔️](cpp%2F50-Pow-X-N.cpp)</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>[✔️](javascript%2F50.%20Pow(x%2C%20n).js)</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>[✔️](python%2F509-Fibonacci-Number.py)</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>[✔️](typescript%2F50-Pow.ts)</div></sub>
406-
<sub>[43 - Multiply Strings](https://leetcode.com/problems/multiply-strings/)</sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>[✔️](cpp%2F43-Multiply-Strings.cpp)</div></sub> | <sub><div align='center'>[✔️](csharp%2F43-Multiply-Strings.cs)</div></sub> | <sub><div align='center'>[✔️](go%2F435-Non-Overlapping-Intervals.go)</div></sub> | <sub><div align='center'>[✔️](java%2F43-Multiply-Strings.java)</div></sub> | <sub><div align='center'>[✔️](javascript%2F43-Multiply-Strings.js)</div></sub> | <sub><div align='center'></div></sub> | <sub><div align='center'>[✔️](python%2F43-Multiply-Strings.py)</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>[✔️](scala%2F435-Non-Overlapping-Intervals.scala)</div></sub> | <sub><div align='center'>[✔️](swift%2F43-Multiply-Strings.swift)</div></sub> | <sub><div align='center'>[✔️](typescript%2F43-Multiply-Strings.ts)</div></sub>
406+
<sub>[43 - Multiply Strings](https://leetcode.com/problems/multiply-strings/)</sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>[✔️](cpp%2F43-Multiply-Strings.cpp)</div></sub> | <sub><div align='center'>[✔️](csharp%2F43-Multiply-Strings.cs)</div></sub> | <sub><div align='center'>[✔️](go%2F435-Non-Overlapping-Intervals.go)</div></sub> | <sub><div align='center'>[✔️](java%2F43-Multiply-Strings.java)</div></sub> | <sub><div align='center'>[✔️](javascript%2F43-Multiply-Strings.js)</div></sub> | <sub><div align='center'>[✔️](kotlin%2F438-Find-All-Anagrams-In-A-String.kt)</div></sub> | <sub><div align='center'>[✔️](python%2F43-Multiply-Strings.py)</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>[✔️](scala%2F435-Non-Overlapping-Intervals.scala)</div></sub> | <sub><div align='center'>[✔️](swift%2F43-Multiply-Strings.swift)</div></sub> | <sub><div align='center'>[✔️](typescript%2F43-Multiply-Strings.ts)</div></sub>
407407
<sub>[2013 - Detect Squares](https://leetcode.com/problems/detect-squares/)</sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>[✔️](cpp%2F2013-Detect-Squares.cpp)</div></sub> | <sub><div align='center'>[✔️](csharp%2F2013-Detect-Squares.cs)</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>[✔️](java%2F2013-Detect-Squares.java)</div></sub> | <sub><div align='center'>[✔️](javascript%2F2013-Detect-Squares.js)</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>[✔️](python%2F2013-Detect-Squares.py)</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub>
408408
<sub>[1041 - Robot Bounded In Circle](https://leetcode.com/problems/robot-bounded-in-circle/)</sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>❌</div></sub>
409409
<sub>[6 - Zigzag Conversion](https://leetcode.com/problems/zigzag-conversion/)</sub> | <sub><div align='center'>[✔️](c%2F605-Can-Place-Flowers.c)</div></sub> | <sub><div align='center'>[✔️](cpp%2F605-Can-Place-Flowers.cpp)</div></sub> | <sub><div align='center'>[✔️](csharp%2F62-Unique-Paths.cs)</div></sub> | <sub><div align='center'>[✔️](go%2F62-Unique-Paths.go)</div></sub> | <sub><div align='center'>[✔️](java%2F6-Zigzag-Conversion.java)</div></sub> | <sub><div align='center'>[✔️](javascript%2F605-can-place-flowers.js)</div></sub> | <sub><div align='center'>[✔️](kotlin%2F62-Unique-Paths.kt)</div></sub> | <sub><div align='center'>[✔️](python%2F605-Can-Place-Flowers.py)</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>[✔️](rust%2F62-Unique-Paths.rs)</div></sub> | <sub><div align='center'>❌</div></sub> | <sub><div align='center'>[✔️](swift%2F66-Plus-One.swift)</div></sub> | <sub><div align='center'>[✔️](typescript%2F605-Can-Place-Flowers.ts)</div></sub>

cpp/665-Non-decreasing-Array.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
public:
3+
bool checkPossibility(vector<int>& nums) {
4+
bool changed = false;
5+
6+
for(int i = 0; i < nums.size() - 1; i++){
7+
if(nums[i] <= nums[i+1]){
8+
continue;
9+
}
10+
if(changed){
11+
return false;
12+
}
13+
14+
if(i == 0 || nums[i+1] >= nums[i-1]){
15+
nums[i] = nums[i+1];
16+
}
17+
else{
18+
nums[i+1] = nums[i];
19+
}
20+
changed = true;
21+
}
22+
23+
return true;
24+
}
25+
};

javascript/0283-move-zeroes.js

+26
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
/**
2+
* Two Pointer
3+
* Time O(N) | Space O(N)
4+
* https://leetcode.com/problems/move-zeroes/
5+
* @param {number[]} nums
6+
* @return {void} Do not return anything, modify nums in-place instead.
7+
*/
8+
var moveZeroes = function(nums) {
9+
10+
const arr = new Array(nums.length).fill(0);
11+
12+
let [left, right] = [0, 0];
13+
14+
while (right < nums.length) {
15+
const isZero = (nums[right] === 0);
16+
if (!isZero) {
17+
arr[left] = nums[right];
18+
left++;
19+
}
20+
21+
right++;
22+
}
23+
24+
return arr;
25+
};
26+
127
/**
228
* 2 Pointer
329
* Time O(N) | Space O(1)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Solution {
2+
fun findAnagrams(s: String, p: String): List<Int> {
3+
4+
val pCount = IntArray(26)
5+
val res = ArrayList<Int>()
6+
7+
for(c in p)
8+
pCount[c - 'a']++
9+
10+
var start = 0
11+
var end = 0
12+
13+
while(end < s.length){
14+
// increase the window
15+
if(pCount[s[end] - 'a'] > 0){
16+
pCount[s[end++] - 'a']--
17+
if(end-start == p.length)
18+
res.add(start)
19+
// window size 0? step to next
20+
}else if(start == end){
21+
start++
22+
end++
23+
//decrease the window
24+
}else{
25+
pCount[s[start++] - 'a']++
26+
}
27+
}
28+
29+
return res
30+
}
31+
}

0 commit comments

Comments
 (0)