Skip to content

Commit

Permalink
Merge branch 'main' into nc-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
neetcode-gh committed Dec 28, 2022
2 parents 77d60ff + 230f2c9 commit 71a23e0
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ If you would like to have collaborator permissions on the repo to merge your own
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
Expand Down Expand Up @@ -403,7 +403,7 @@ If you would like to have collaborator permissions on the repo to merge your own
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
Expand Down
25 changes: 25 additions & 0 deletions cpp/665-Non-decreasing-Array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Solution {
public:
bool checkPossibility(vector<int>& nums) {
bool changed = false;

for(int i = 0; i < nums.size() - 1; i++){
if(nums[i] <= nums[i+1]){
continue;
}
if(changed){
return false;
}

if(i == 0 || nums[i+1] >= nums[i-1]){
nums[i] = nums[i+1];
}
else{
nums[i+1] = nums[i];
}
changed = true;
}

return true;
}
};
26 changes: 26 additions & 0 deletions javascript/0283-move-zeroes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
/**
* Two Pointer
* Time O(N) | Space O(N)
* https://leetcode.com/problems/move-zeroes/
* @param {number[]} nums
* @return {void} Do not return anything, modify nums in-place instead.
*/
var moveZeroes = function(nums) {

const arr = new Array(nums.length).fill(0);

let [left, right] = [0, 0];

while (right < nums.length) {
const isZero = (nums[right] === 0);
if (!isZero) {
arr[left] = nums[right];
left++;
}

right++;
}

return arr;
};

/**
* 2 Pointer
* Time O(N) | Space O(1)
Expand Down
31 changes: 31 additions & 0 deletions kotlin/438-Find-All-Anagrams-In-A-String.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class Solution {
fun findAnagrams(s: String, p: String): List<Int> {

val pCount = IntArray(26)
val res = ArrayList<Int>()

for(c in p)
pCount[c - 'a']++

var start = 0
var end = 0

while(end < s.length){
// increase the window
if(pCount[s[end] - 'a'] > 0){
pCount[s[end++] - 'a']--
if(end-start == p.length)
res.add(start)
// window size 0? step to next
}else if(start == end){
start++
end++
//decrease the window
}else{
pCount[s[start++] - 'a']++
}
}

return res
}
}

0 comments on commit 71a23e0

Please sign in to comment.