diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000..22d8733da
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,165 @@
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# User-specific files
+*.suo
+*.user
+*.sln.docstates
+
+# Build results
+
+[Dd]ebug/
+[Rr]elease/
+x64/
+[Bb]in/
+[Oo]bj/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+*_i.c
+*_p.c
+*_i.h
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.log
+*.svclog
+*.scc
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opensdf
+*.sdf
+*.cachefile
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.Publish.xml
+*.pubxml
+*.azurePubxml
+
+# NuGet Packages Directory
+## TODO: If you have NuGet Package Restore enabled, uncomment the next line
+packages/
+## TODO: If the tool you use requires repositories.config, also uncomment the next line
+!packages/repositories.config
+
+# Windows Azure Build Output
+csx/
+*.build.csdef
+
+# Windows Store app package directory
+AppPackages/
+
+# Others
+sql/
+*.Cache
+ClientBin/
+[Ss]tyle[Cc]op.*
+![Ss]tyle[Cc]op.targets
+~$*
+*~
+*.dbmdl
+*.[Pp]ublish.xml
+
+*.publishsettings
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file to a newer
+# Visual Studio version. Backup files are not needed, because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+
+# SQL Server files
+App_Data/*.mdf
+App_Data/*.ldf
+
+# =========================
+# Windows detritus
+# =========================
+
+# Windows image file caches
+Thumbs.db
+ehthumbs.db
+
+# Folder config file
+Desktop.ini
+
+# Recycle Bin used on file shares
+$RECYCLE.BIN/
+
+# Mac desktop service store files
+.DS_Store
+
+_NCrunch*
+.vscode/launch.json
+.vscode/tasks.json
+
+/csharp/.vs/
+/.vs/slnx.sqlite
+/.vs/VSWorkspaceState.json
+
+# Default ignored files
+/shelf/
+/workspace.xml
+# Rider ignored files
+/projectSettingsUpdater.xml
+/contentModel.xml
+/modules.xml
+/.idea.main.iml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
+
+.idea/.idea.leetcode-CSharp.dir/.idea/vcs.xml
+.idea/.idea.leetcode-CSharp.dir/.idea/indexLayout.xml
+.idea/.idea.leetcode-CSharp.dir/.idea/projectSettingsUpdater.xml
+.idea/.idea.leetcode-CSharp.dir/.idea/workspace.xml
+
+csharp/.idea/.idea.main/.idea/projectSettingsUpdater.xml
+csharp/.idea/.idea.main/.idea/workspace.xml
+csharp/.idea/.idea.main/.idea/.name
+csharp/.idea/.idea.main/.idea/indexLayout.xml
+csharp/.idea/.idea.main/.idea/vcs.xml
+csharp/.idea/.idea.Neetcode/.idea
diff --git a/1-Two-Sum.py b/1-Two-Sum.py
deleted file mode 100644
index 3eb8df064..000000000
--- a/1-Two-Sum.py
+++ /dev/null
@@ -1,9 +0,0 @@
-class Solution:
- def twoSum(self, nums: List[int], target: int) -> List[int]:
- prevMap = {} # val -> index
-
- for i, n in enumerate(nums):
- diff = target - n
- if diff in prevMap:
- return [prevMap[diff], i]
- prevMap[n] = i
diff --git a/10-Regular-Expression-Matching.py b/10-Regular-Expression-Matching.py
deleted file mode 100644
index b4d2a68e8..000000000
--- a/10-Regular-Expression-Matching.py
+++ /dev/null
@@ -1,45 +0,0 @@
-# BOTTOM-UP Dynamic Programming
-class Solution:
- def isMatch(self, s: str, p: str) -> bool:
- cache = [[False] * (len(p) + 1) for i in range(len(s) + 1)]
- cache[len(s)][len(p)] = True
-
- for i in range(len(s), -1, -1):
- for j in range(len(p) - 1, -1 ,-1):
- match = i < len(s) and (s[i] == p[j] or p[j] == ".")
-
- if (j + 1) < len(p) and p[j + 1] == "*":
- cache[i][j] = cache[i][j + 2]
- if match:
- cache[i][j] = cache[i + 1][j] or cache[i][j]
- elif match:
- cache[i][j] = cache[i+1][j+1]
-
- return cache[0][0]
-
-
-# TOP DOWN MEMOIZATION
-class Solution:
- def isMatch(self, s: str, p: str) -> bool:
- cache = {}
-
- def dfs(i, j):
- if (i, j) in cache:
- return cache[(i, j)]
- if i >= len(s) and j >= len(p):
- return True
- if j >= len(p):
- return False
-
- match = i < len(s) and (s[i] == p[j] or p[j] == ".")
- if (j + 1) < len(p) and p[j + 1] == "*":
- cache[(i, j)] = (dfs(i, j + 2) or # dont use *
- (match and dfs(i + 1, j))) # use *
- return cache[(i, j)]
- if match:
- cache[(i,j)] = dfs(i + 1, j + 1)
- return cache[(i,j)]
- cache[(i,j)] = False
- return False
-
- return dfs(0, 0)
diff --git a/100-Same-Tree.py b/100-Same-Tree.py
deleted file mode 100644
index e054ed268..000000000
--- a/100-Same-Tree.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# Definition for a binary tree node.
-# class TreeNode:
-# def __init__(self, x):
-# self.val = x
-# self.left = None
-# self.right = None
-
-class Solution:
- def isSameTree(self, p: TreeNode, q: TreeNode) -> bool:
- if not p and not q: return True
- if p and q and p.val == q.val:
- return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
- else: return False
diff --git a/102-Binary-Tree-Level-Order-Traversal.py b/102-Binary-Tree-Level-Order-Traversal.py
deleted file mode 100644
index 491c1406f..000000000
--- a/102-Binary-Tree-Level-Order-Traversal.py
+++ /dev/null
@@ -1,23 +0,0 @@
-# Definition for a binary tree node.
-# class TreeNode:
-# def __init__(self, x):
-# self.val = x
-# self.left = None
-# self.right = None
-
-class Solution:
- def levelOrder(self, root: TreeNode) -> List[List[int]]:
- res = []
- q = collections.deque()
- if root: q.append(root)
-
- while q:
- val = []
-
- for i in range(len(q)):
- node = q.popleft()
- val.append(node.val)
- if node.left: q.append(node.left)
- if node.right: q.append(node.right)
- res.append(val)
- return res
diff --git a/104-Maximum-Depth-of-Binary-Tree.py b/104-Maximum-Depth-of-Binary-Tree.py
deleted file mode 100644
index b02eb54dc..000000000
--- a/104-Maximum-Depth-of-Binary-Tree.py
+++ /dev/null
@@ -1,41 +0,0 @@
-# RECURSIVE DFS
-class Solution:
- def maxDepth(self, root: TreeNode) -> int:
- if not root:
- return 0
-
- return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))
-
-# ITERATIVE DFS
-class Solution:
- def maxDepth(self, root: TreeNode) -> int:
- stack = [[root, 1]]
- res = 0
-
- while stack:
- node, depth = stack.pop()
-
- if node:
- res = max(res, depth)
- stack.append([node.left, depth + 1])
- stack.append([node.right, depth + 1])
- return res
-
-# BFS
-class Solution:
- def maxDepth(self, root: TreeNode) -> int:
- if not root:
- return 0
-
- level = 0
- q = deque([root])
- while q:
-
- for i in range(len(q)):
- node = q.popleft()
- if node.left:
- q.append(node.left)
- if node.right:
- q.append(node.right)
- level += 1
- return level
diff --git a/1046-Last-Stone-Weight.py b/1046-Last-Stone-Weight.py
deleted file mode 100644
index e1cc3c015..000000000
--- a/1046-Last-Stone-Weight.py
+++ /dev/null
@@ -1,13 +0,0 @@
-class Solution:
- def lastStoneWeight(self, stones: List[int]) -> int:
- stones = [-s for s in stones]
- heapq.heapify(stones)
-
- while len(stones) > 1:
- first = heapq.heappop(stones)
- second = heapq.heappop(stones)
- if second > first:
- heapq.heappush(stones, first - second)
-
- stones.append(0)
- return abs(stones[0])
diff --git a/105-Construct-Binary-Tree-from-Preorder-and-Inorder-Traversal.py b/105-Construct-Binary-Tree-from-Preorder-and-Inorder-Traversal.py
deleted file mode 100644
index 570d3cee5..000000000
--- a/105-Construct-Binary-Tree-from-Preorder-and-Inorder-Traversal.py
+++ /dev/null
@@ -1,10 +0,0 @@
-class Solution:
- def buildTree(self, preorder: List[int], inorder: List[int]) -> Optional[TreeNode]:
- if not preorder or not inorder:
- return None
-
- root = TreeNode(preorder[0])
- mid = inorder.index(preorder[0])
- root.left = self.buildTree(preorder[1:mid + 1], inorder[:mid])
- root.right = self.buildTree(preorder[mid + 1:], inorder[mid + 1:])
- return root
diff --git a/11-Container-With-Most-Water.py b/11-Container-With-Most-Water.py
deleted file mode 100644
index e9607306c..000000000
--- a/11-Container-With-Most-Water.py
+++ /dev/null
@@ -1,12 +0,0 @@
-class Solution:
- def maxArea(self, height: List[int]) -> int:
- l, r = 0, len(height) - 1
- res = 0
-
- while l < r:
- res = max(res, min(height[l], height[r]) * (r - l))
- if height[l] < height[r]:
- l += 1
- elif height[r] <= height[l]:
- r -= 1
- return res
diff --git a/110-Balanced-Binary-Tree.py b/110-Balanced-Binary-Tree.py
deleted file mode 100644
index ffd200329..000000000
--- a/110-Balanced-Binary-Tree.py
+++ /dev/null
@@ -1,17 +0,0 @@
-# Definition for a binary tree node.
-# class TreeNode:
-# def __init__(self, val=0, left=None, right=None):
-# self.val = val
-# self.left = left
-# self.right = right
-class Solution:
- def isBalanced(self, root: Optional[TreeNode]) -> bool:
-
- def dfs(root):
- if not root: return [True, 0]
-
- left, right = dfs(root.left), dfs(root.right)
- balanced = (left[0] and right[0] and
- abs(left[1] - right[1]) <= 1)
- return [balanced, 1 + max(left[1], right[1])]
- return dfs(root)[0]
diff --git a/1143-Longest-Common-Subsequence.py b/1143-Longest-Common-Subsequence.py
deleted file mode 100644
index 77af92b4a..000000000
--- a/1143-Longest-Common-Subsequence.py
+++ /dev/null
@@ -1,12 +0,0 @@
-class Solution:
- def longestCommonSubsequence(self, text1: str, text2: str) -> int:
- dp = [[0 for j in range(len(text2) + 1)] for i in range(len(text1) + 1)]
-
- for i in range(len(text1) - 1, -1, -1):
- for j in range(len(text2) - 1, -1, -1):
- if text1[i] == text2[j]:
- dp[i][j] = 1 + dp[i + 1][j + 1]
- else:
- dp[i][j] = max(dp[i][j + 1], dp[i + 1][j])
-
- return dp[0][0]
diff --git a/115-Distinct-Subsequences.py b/115-Distinct-Subsequences.py
deleted file mode 100644
index 67f0172fc..000000000
--- a/115-Distinct-Subsequences.py
+++ /dev/null
@@ -1,16 +0,0 @@
-class Solution:
- def numDistinct(self, s: str, t: str) -> int:
- cache = {}
-
- for i in range(len(s) + 1):
- cache[(i, len(t))] = 1
- for j in range(len(t)):
- cache[(len(s), j)] = 0
-
- for i in range(len(s) - 1, -1, -1):
- for j in range(len(t) - 1, -1, -1):
- if s[i] == t[j]:
- cache[(i, j)] = cache[(i+1,j+1)] + cache[(i+1,j)]
- else:
- cache[(i,j)] = cache[(i+1,j)]
- return cache[(0,0)]
diff --git a/12-Integer-To-Roman.py b/12-Integer-To-Roman.py
deleted file mode 100644
index 50d5393ca..000000000
--- a/12-Integer-To-Roman.py
+++ /dev/null
@@ -1,13 +0,0 @@
-class Solution:
- def intToRoman(self, num: int) -> str:
- symList = [["I", 1], ["IV" , 4], ["V" , 5], ["IX" , 9],
- ["X" , 10], ["XL" , 40], ["L" , 50], ["XC" , 90],
- ["C" , 100], ["CD", 400], ["D", 500], ["CM", 900],
- ["M" , 1000]]
- res = ""
- for sym, val in reversed(symList):
- if num // val:
- count = num // val
- res += (sym * count)
- num = num % val
- return res
diff --git a/121-Best-Time-To-Buy-and-Sell-Stock.py b/121-Best-Time-To-Buy-and-Sell-Stock.py
deleted file mode 100644
index 43f25e419..000000000
--- a/121-Best-Time-To-Buy-and-Sell-Stock.py
+++ /dev/null
@@ -1,10 +0,0 @@
-class Solution:
- def maxProfit(self, prices: List[int]) -> int:
- res = 0
-
- l = 0
- for r in range(1, len(prices)):
- if prices[r] < prices[l]:
- l = r
- res = max(res, prices[r] - prices[l])
- return res
diff --git a/1239-Maximum-Length-of-a-Concatenated-String-with-Unique-Characters.py b/1239-Maximum-Length-of-a-Concatenated-String-with-Unique-Characters.py
deleted file mode 100644
index 5c5628285..000000000
--- a/1239-Maximum-Length-of-a-Concatenated-String-with-Unique-Characters.py
+++ /dev/null
@@ -1,27 +0,0 @@
-class Solution:
- def maxLength(self, arr: List[str]) -> int:
- charSet = set()
-
- def overlap(charSet, s):
- c = Counter(charSet) + Counter(s)
- return max(c.values()) > 1
- # prev = set()
- # for c in s:
- # if c in charSet or c in prev:
- # return True
- # prev.add(c)
- # return False
-
- def backtrack(i):
- if i == len(arr):
- return len(charSet)
- res = 0
- if not overlap(charSet, arr[i]):
- for c in arr[i]:
- charSet.add(c)
- res = backtrack(i + 1)
- for c in arr[i]:
- charSet.remove(c)
- return max(res, backtrack(i + 1)) # dont concatenate arr[i]
-
- return backtrack(0)
diff --git a/124-Binary-Tree-Maximum-Path-Sum.py b/124-Binary-Tree-Maximum-Path-Sum.py
deleted file mode 100644
index e79190ced..000000000
--- a/124-Binary-Tree-Maximum-Path-Sum.py
+++ /dev/null
@@ -1,26 +0,0 @@
-# Definition for a binary tree node.
-# class TreeNode:
-# def __init__(self, val=0, left=None, right=None):
-# self.val = val
-# self.left = left
-# self.right = right
-class Solution:
- def maxPathSum(self, root: TreeNode) -> int:
- res = [root.val]
-
- # return max path sum without split
- def dfs(root):
- if not root:
- return 0
-
- leftMax = dfs(root.left)
- rightMax = dfs(root.right)
- leftMax = max(leftMax, 0)
- rightMax = max(rightMax, 0)
-
- # compute max path sum WITH split
- res[0] = max(res[0], root.val + leftMax + rightMax)
- return root.val + max(leftMax, rightMax)
-
- dfs(root)
- return res[0]
diff --git a/125-Valid-Palindrome.py b/125-Valid-Palindrome.py
deleted file mode 100644
index 31723b3d7..000000000
--- a/125-Valid-Palindrome.py
+++ /dev/null
@@ -1,19 +0,0 @@
-class Solution:
- def isPalindrome(self, s: str) -> bool:
- l, r = 0, len(s) - 1
- while l < r:
- while l < r and not self.alphanum(s[l]):
- l += 1
- while l < r and not self.alphanum(s[r]):
- r -= 1
- if s[l].lower() != s[r].lower():
- return False
- l += 1
- r -= 1
- return True
-
- # Could write own alpha-numeric function
- def alphanum(self, c):
- return (ord('A') <= ord(c) <= ord('Z') or
- ord('a') <= ord(c) <= ord('z') or
- ord('0') <= ord(c) <= ord('9'))
diff --git a/127-Word-Ladder.py b/127-Word-Ladder.py
deleted file mode 100644
index e117b2a7b..000000000
--- a/127-Word-Ladder.py
+++ /dev/null
@@ -1,28 +0,0 @@
-class Solution:
- def ladderLength(self, beginWord: str, endWord: str, wordList: List[str]) -> int:
- if endWord not in wordList:
- return 0
-
- nei = collections.defaultdict(list)
- wordList.append(beginWord)
- for word in wordList:
- for j in range(len(word)):
- pattern = word[:j] + "*" + word[j + 1:]
- nei[pattern].append(word)
-
- visit = set([beginWord])
- q = deque([beginWord])
- res = 1
- while q:
- for i in range(len(q)):
- word = q.popleft()
- if word == endWord:
- return res
- for j in range(len(word)):
- pattern = word[:j] + "*" + word[j + 1:]
- for neiWord in nei[pattern]:
- if neiWord not in visit:
- visit.add(neiWord)
- q.append(neiWord)
- res += 1
- return 0
diff --git a/128-Longest-consecutive-sequence.py b/128-Longest-consecutive-sequence.py
deleted file mode 100644
index 0c878a200..000000000
--- a/128-Longest-consecutive-sequence.py
+++ /dev/null
@@ -1,14 +0,0 @@
-class Solution:
- def longestConsecutive(self, nums: List[int]) -> int:
- numSet = set(nums)
- longest = 0
-
- for n in nums:
- # check if its the start of a sequence
- if (n - 1) not in numSet:
- length = 1
- while (n + length) in numSet:
- length += 1
- longest = max(length, longest)
- return longest
-
diff --git a/13-Roman-To-Integer.py b/13-Roman-To-Integer.py
deleted file mode 100644
index 3bd3a2abb..000000000
--- a/13-Roman-To-Integer.py
+++ /dev/null
@@ -1,11 +0,0 @@
-class Solution:
- def romanToInt(self, s: str) -> int:
- roman = { "I" : 1, "V" : 5, "X" : 10,
- "L" : 50, "C" : 100, "D" : 500, "M" : 1000 }
- res = 0
- for i in range(len(s)):
- if i + 1 < len(s) and roman[s[i]] < roman[s[i + 1]]:
- res -= roman[s[i]]
- else:
- res += roman[s[i]]
- return res
diff --git a/130-Surrounded-Regions.py b/130-Surrounded-Regions.py
deleted file mode 100644
index dfbb8308a..000000000
--- a/130-Surrounded-Regions.py
+++ /dev/null
@@ -1,32 +0,0 @@
-class Solution:
- def solve(self, board: List[List[str]]) -> None:
- ROWS, COLS = len(board), len(board[0])
-
- def capture(r, c):
- if (r < 0 or c < 0 or r == ROWS or c == COLS
- or board[r][c] != "O"):
- return
- board[r][c] = "T"
- capture(r + 1, c)
- capture(r - 1, c)
- capture(r, c + 1)
- capture(r, c - 1)
-
- # 1. (DFS) Capture unsurrounded regions (O -> T)
- for r in range(ROWS):
- for c in range(COLS):
- if (board[r][c] == "O" and
- (r in [0, ROWS - 1] or c in [0, COLS - 1])):
- capture(r, c)
-
- # 2. Capture surrounded regions (O -> X)
- for r in range(ROWS):
- for c in range(COLS):
- if board[r][c] == "O":
- board[r][c] = "X"
-
- # 3. Uncapture unsurrounded regions (T -> O)
- for r in range(ROWS):
- for c in range(COLS):
- if board[r][c] == "T":
- board[r][c] = "O"
diff --git a/131-Palindrome-Partitioning.py b/131-Palindrome-Partitioning.py
deleted file mode 100644
index 21df07917..000000000
--- a/131-Palindrome-Partitioning.py
+++ /dev/null
@@ -1,22 +0,0 @@
-class Solution:
- def partition(self, s: str) -> List[List[str]]:
- res, part = [], []
-
- def dfs(i):
- if i >= len(s):
- res.append(part.copy())
- return
- for j in range(i, len(s)):
- if self.isPali(s, i, j):
- part.append(s[i:j+1])
- dfs(j + 1)
- part.pop()
- dfs(0)
- return res
-
- def isPali(self, s, l, r):
- while l < r:
- if s[l] != s[r]:
- return False
- l, r = l + 1, r - 1
- return True
diff --git a/133-Clone-Graph.py b/133-Clone-Graph.py
deleted file mode 100644
index 36505a209..000000000
--- a/133-Clone-Graph.py
+++ /dev/null
@@ -1,15 +0,0 @@
-class Solution:
- def cloneGraph(self, node: 'Node') -> 'Node':
- oldToNew = {}
-
- def dfs(node):
- if node in oldToNew:
- return oldToNew[node]
-
- copy = Node(node.val)
- oldToNew[node] = copy
- for nei in node.neighbors:
- copy.neighbors.append(dfs(nei))
- return copy
-
- return dfs(node) if node else None
diff --git a/134-Gas-Station.py b/134-Gas-Station.py
deleted file mode 100644
index 2e90d2a7b..000000000
--- a/134-Gas-Station.py
+++ /dev/null
@@ -1,14 +0,0 @@
-class Solution:
- def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int:
- start, end = len(gas) - 1, 0
- total = gas[start] - cost[start]
-
- while start >= end:
- while total < 0 and start >= end:
- start -= 1
- total += (gas[start] - cost[start])
- if start == end:
- return start
- total += (gas[end] - cost[end])
- end += 1
- return -1
diff --git a/136-Single-Number.py b/136-Single-Number.py
deleted file mode 100644
index 9b6595a24..000000000
--- a/136-Single-Number.py
+++ /dev/null
@@ -1,6 +0,0 @@
-class Solution:
- def singleNumber(self, nums: List[int]) -> int:
- res = 0
- for n in nums:
- res = n ^ res
- return res
diff --git a/138-Copy-List-With-Random-Pointer.py b/138-Copy-List-With-Random-Pointer.py
deleted file mode 100644
index 386fd1a41..000000000
--- a/138-Copy-List-With-Random-Pointer.py
+++ /dev/null
@@ -1,25 +0,0 @@
-"""
-# Definition for a Node.
-class Node:
- def __init__(self, x: int, next: 'Node' = None, random: 'Node' = None):
- self.val = int(x)
- self.next = next
- self.random = random
-"""
-
-class Solution:
- def copyRandomList(self, head: 'Node') -> 'Node':
- oldToCopy = { None : None }
-
- cur = head
- while cur:
- copy = Node(cur.val)
- oldToCopy[cur] = copy
- cur = cur.next
- cur = head
- while cur:
- copy = oldToCopy[cur]
- copy.next = oldToCopy[cur.next]
- copy.random = oldToCopy[cur.random]
- cur = cur.next
- return oldToCopy[head]
diff --git a/139-Word-Break.py b/139-Word-Break.py
deleted file mode 100644
index ae5d2e972..000000000
--- a/139-Word-Break.py
+++ /dev/null
@@ -1,14 +0,0 @@
-class Solution:
- def wordBreak(self, s: str, wordDict: List[str]) -> bool:
-
- dp = [False] * (len(s) + 1)
- dp[len(s)] = True
-
- for i in range(len(s) - 1, -1, -1):
- for w in wordDict:
- if (i + len(w)) <= len(s) and s[i : i + len(w)] == w:
- dp[i] = dp[i + len(w)]
- if dp[i]:
- break
-
- return dp[0]
diff --git a/141-Linked-List-Cycle.py b/141-Linked-List-Cycle.py
deleted file mode 100644
index 6758f32a4..000000000
--- a/141-Linked-List-Cycle.py
+++ /dev/null
@@ -1,16 +0,0 @@
-# Definition for singly-linked list.
-# class ListNode:
-# def __init__(self, x):
-# self.val = x
-# self.next = None
-
-class Solution:
- def hasCycle(self, head: ListNode) -> bool:
- slow, fast = head, head
-
- while fast and fast.next:
- slow = slow.next
- fast = fast.next.next
- if slow == fast:
- return True
- return False
diff --git a/143-Reorder-List.py b/143-Reorder-List.py
deleted file mode 100644
index 9b210b7c6..000000000
--- a/143-Reorder-List.py
+++ /dev/null
@@ -1,24 +0,0 @@
-class Solution:
- def reorderList(self, head: ListNode) -> None:
- # find middle
- slow, fast = head, head.next
- while fast and fast.next:
- slow = slow.next
- fast = fast.next.next
-
- # reverse second half
- second = slow.next
- prev = slow.next = None
- while second:
- tmp = second.next
- second.next = prev
- prev = second
- second = tmp
-
- # merge two halfs
- first, second = head, prev
- while second:
- tmp1, tmp2 = first.next, second.next
- first.next = second
- second.next = tmp1
- first, second = tmp1, tmp2
diff --git a/1448-Count-Good-Nodes-in-Binary-Tree.py b/1448-Count-Good-Nodes-in-Binary-Tree.py
deleted file mode 100644
index 6b3325122..000000000
--- a/1448-Count-Good-Nodes-in-Binary-Tree.py
+++ /dev/null
@@ -1,20 +0,0 @@
-# Definition for a binary tree node.
-# class TreeNode:
-# def __init__(self, val=0, left=None, right=None):
-# self.val = val
-# self.left = left
-# self.right = right
-class Solution:
- def goodNodes(self, root: TreeNode) -> int:
-
- def dfs(node, maxVal):
- if not node:
- return 0
-
- res = 1 if node.val >= maxVal else 0
- maxVal = max(maxVal, node.val)
- res += dfs(node.left, maxVal)
- res += dfs(node.right, maxVal)
- return res
-
- return dfs(root, root.val)
diff --git a/146-LRU-Cache.py b/146-LRU-Cache.py
deleted file mode 100644
index cd06aed11..000000000
--- a/146-LRU-Cache.py
+++ /dev/null
@@ -1,44 +0,0 @@
-class Node:
- def __init__(self, key, val):
- self.key, self.val = key, val
- self.prev = self.next = None
-
-class LRUCache:
-
- def __init__(self, capacity: int):
- self.cap = capacity
- self.cache = {} # map key to node
-
- self.left, self.right = Node(0, 0), Node(0, 0)
- self.left.next, self.right.prev = self.right, self.left
-
- # remove node from list
- def remove(self, node):
- prev, nxt = node.prev, node.next
- prev.next, nxt.prev = nxt, prev
-
- # insert node at right
- def insert(self, node):
- prev, nxt = self.right.prev, self.right
- prev.next = nxt.prev = node
- node.next, node.prev = nxt, prev
-
- def get(self, key: int) -> int:
- if key in self.cache:
- self.remove(self.cache[key])
- self.insert(self.cache[key])
- return self.cache[key].val
- return -1
-
- def put(self, key: int, value: int) -> None:
- if key in self.cache:
- self.remove(self.cache[key])
- self.cache[key] = Node(key, value)
- self.insert(self.cache[key])
-
- if len(self.cache) > self.cap:
- # remove from the list and delete the LRU from hashmap
- lru = self.left.next
- self.remove(lru)
- print(lru in self.cache)
- del self.cache[lru.key]
diff --git a/15-3Sum.py b/15-3Sum.py
deleted file mode 100644
index e8e256717..000000000
--- a/15-3Sum.py
+++ /dev/null
@@ -1,22 +0,0 @@
-class Solution:
- def threeSum(self, nums: List[int]) -> List[List[int]]:
- res = []
- nums.sort()
-
- for i, a in enumerate(nums):
- if i > 0 and a == nums[i - 1]:
- continue
-
- l, r = i + 1, len(nums) - 1
- while l < r:
- threeSum = a + nums[l] + nums[r]
- if threeSum > 0:
- r -= 1
- elif threeSum < 0:
- l += 1
- else:
- res.append([a, nums[l], nums[r]])
- l += 1
- while nums[l] == nums[l - 1] and l < r:
- l += 1
- return res
diff --git a/150-Evaluate-Reverse-Polish-Notation.py b/150-Evaluate-Reverse-Polish-Notation.py
deleted file mode 100644
index f75f2b774..000000000
--- a/150-Evaluate-Reverse-Polish-Notation.py
+++ /dev/null
@@ -1,17 +0,0 @@
-class Solution:
- def evalRPN(self, tokens: List[str]) -> int:
- stack = []
- for c in tokens:
- if c == "+":
- stack.append(stack.pop() + stack.pop())
- elif c == "-":
- a, b = stack.pop(), stack.pop()
- stack.append(b - a)
- elif c == "*":
- stack.append(stack.pop() * stack.pop())
- elif c == "/":
- a, b = stack.pop(), stack.pop()
- stack.append(int(b / a))
- else:
- stack.append(int(c))
- return stack[0]
diff --git a/152-Maximum-Product-Subarray.py b/152-Maximum-Product-Subarray.py
deleted file mode 100644
index 5297e1fbe..000000000
--- a/152-Maximum-Product-Subarray.py
+++ /dev/null
@@ -1,13 +0,0 @@
-class Solution:
- def maxProduct(self, nums: List[int]) -> int:
- # O(n)/O(1) : Time/Memory
- res = max(nums)
- curMin, curMax = 1, 1
-
- for n in nums:
-
- tmp = curMax * n
- curMax = max(n * curMax, n * curMin, n)
- curMin = min(tmp, n * curMin, n)
- res = max(res, curMax)
- return res
diff --git a/153-Find-Minimum-in-Rotated-Sorted-Array.py b/153-Find-Minimum-in-Rotated-Sorted-Array.py
deleted file mode 100644
index 8b4caf773..000000000
--- a/153-Find-Minimum-in-Rotated-Sorted-Array.py
+++ /dev/null
@@ -1,16 +0,0 @@
-class Solution:
- def findMin(self, nums: List[int]) -> int:
- res = nums[0]
- l, r = 0, len(nums) - 1
-
- while l <= r:
- if nums[l] < nums[r]:
- res = min(res, nums[l])
- break
- m = (l + r) // 2
- res = min(res, nums[m])
- if nums[m] >= nums[l]:
- l = m + 1
- else:
- r = m - 1
- return res
diff --git a/155-Min-Stack.py b/155-Min-Stack.py
deleted file mode 100644
index f0789b4c4..000000000
--- a/155-Min-Stack.py
+++ /dev/null
@@ -1,20 +0,0 @@
-class MinStack:
-
- def __init__(self):
- self.stack = []
- self.minStack = []
-
- def push(self, val: int) -> None:
- self.stack.append(val)
- val = min(val, self.minStack[-1] if self.minStack else val)
- self.minStack.append(val)
-
- def pop(self) -> None:
- self.stack.pop()
- self.minStack.pop()
-
- def top(self) -> int:
- return self.stack[-1]
-
- def getMin(self) -> int:
- return self.minStack[-1]
diff --git a/1584-Min-Cost-to-Connect-all-Points.py b/1584-Min-Cost-to-Connect-all-Points.py
deleted file mode 100644
index 4126570f7..000000000
--- a/1584-Min-Cost-to-Connect-all-Points.py
+++ /dev/null
@@ -1,26 +0,0 @@
-class Solution:
- def minCostConnectPoints(self, points: List[List[int]]) -> int:
- N = len(points)
- adj = { i:[] for i in range(N) } # i : list of [cost, node]
- for i in range(N):
- x1, y1 = points[i]
- for j in range(i + 1, N):
- x2, y2 = points[j]
- dist = abs(x1 - x2) + abs(y1 - y2)
- adj[i].append([dist, j])
- adj[j].append([dist, i])
-
- # Prim's
- res = 0
- visit = set()
- minH = [[0, 0]] # [cost, point]
- while len(visit) < N:
- cost, i = heapq.heappop(minH)
- if i in visit:
- continue
- res += cost
- visit.add(i)
- for neiCost, nei in adj[i]:
- if nei not in visit:
- heapq.heappush(minH, [neiCost, nei])
- return res
diff --git a/160-Intersection-of-Two-Linked-Lists.py b/160-Intersection-of-Two-Linked-Lists.py
deleted file mode 100644
index d11c79f2f..000000000
--- a/160-Intersection-of-Two-Linked-Lists.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# Definition for singly-linked list.
-# class ListNode:
-# def __init__(self, x):
-# self.val = x
-# self.next = None
-
-class Solution:
- def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> Optional[ListNode]:
- l1, l2 = headA, headB
- while l1 != l2:
- l1 = l1.next if l1 else headB
- l2 = l2.next if l2 else headA
- return l1
diff --git a/167-Two-Sum-II.py b/167-Two-Sum-II.py
deleted file mode 100644
index 47ae0adde..000000000
--- a/167-Two-Sum-II.py
+++ /dev/null
@@ -1,13 +0,0 @@
-class Solution:
- def twoSum(self, numbers: List[int], target: int) -> List[int]:
- l, r = 0, len(numbers) - 1
-
- while l < r:
- curSum = numbers[l] + numbers[r]
-
- if curSum > target:
- r -= 1
- elif curSum < target:
- l += 1
- else:
- return [l + 1, r + 1]
diff --git a/17-Letter-Combinations-of-a-Phone-Number.py b/17-Letter-Combinations-of-a-Phone-Number.py
deleted file mode 100644
index 515bf7247..000000000
--- a/17-Letter-Combinations-of-a-Phone-Number.py
+++ /dev/null
@@ -1,23 +0,0 @@
-class Solution:
- def letterCombinations(self, digits: str) -> List[str]:
- res = []
- digitToChar = { "2": "abc",
- "3": "def",
- "4": "ghi",
- "5": "jkl",
- "6": "mno",
- "7": "qprs",
- "8": "tuv",
- "9": "wxyz" }
-
- def backtrack(i, curStr):
- if len(curStr) == len(digits):
- res.append(curStr)
- return
- for c in digitToChar[digits[i]]:
- backtrack(i + 1, curStr + c)
-
- if digits:
- backtrack(0, "")
-
- return res
diff --git a/1851-Minimum-Interval-to-Include-Each-Query.py b/1851-Minimum-Interval-to-Include-Each-Query.py
deleted file mode 100644
index d10ffe14a..000000000
--- a/1851-Minimum-Interval-to-Include-Each-Query.py
+++ /dev/null
@@ -1,16 +0,0 @@
-class Solution:
- def minInterval(self, intervals: List[List[int]], queries: List[int]) -> List[int]:
- intervals.sort()
- minHeap = []
- res = {}
- i = 0
- for q in sorted(queries):
- while i < len(intervals) and intervals[i][0] <= q:
- l, r = intervals[i]
- heapq.heappush(minHeap, (r - l + 1, r))
- i += 1
-
- while minHeap and minHeap[0][1] < q:
- heapq.heappop(minHeap)
- res[q] = minHeap[0][0] if minHeap else -1
- return [res[q] for q in queries]
diff --git a/1899-Merge-Triplets-to-Form-Target-Triplet.py b/1899-Merge-Triplets-to-Form-Target-Triplet.py
deleted file mode 100644
index 170563995..000000000
--- a/1899-Merge-Triplets-to-Form-Target-Triplet.py
+++ /dev/null
@@ -1,11 +0,0 @@
-class Solution:
- def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:
- good = set()
-
- for t in triplets:
- if t[0] > target[0] or t[1] > target[1] or t[2] > target[2]:
- continue
- for i, v in enumerate(t):
- if v == target[i]:
- good.add(i)
- return len(good) == 3
diff --git a/19-Remove-Nth-node-from-end-of-List.py b/19-Remove-Nth-node-from-end-of-List.py
deleted file mode 100644
index 09c5b9f11..000000000
--- a/19-Remove-Nth-node-from-end-of-List.py
+++ /dev/null
@@ -1,17 +0,0 @@
-class Solution:
- def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
- dummy = ListNode(0, head)
- left = dummy
- right = head
-
- while n > 0:
- right = right.next
- n -= 1
-
- while right:
- left = left.next
- right = right.next
-
- # delete
- left.next = left.next.next
- return dummy.next
diff --git a/190-Reverse-Bits.py b/190-Reverse-Bits.py
deleted file mode 100644
index 84d2b6139..000000000
--- a/190-Reverse-Bits.py
+++ /dev/null
@@ -1,7 +0,0 @@
-class Solution:
- def reverseBits(self, n: int) -> int:
- res = 0
- for i in range(32):
- bit = (n >> i) & 1
- res = res | (bit << (31 - i))
- return res
diff --git a/1905-Count-Sub-Islands.py b/1905-Count-Sub-Islands.py
deleted file mode 100644
index ed0ddea98..000000000
--- a/1905-Count-Sub-Islands.py
+++ /dev/null
@@ -1,27 +0,0 @@
-class Solution:
- def countSubIslands(self, grid1: List[List[int]], grid2: List[List[int]]) -> int:
- ROWS, COLS = len(grid1), len(grid1[0])
- visit = set()
-
- def dfs(r, c):
- if (r < 0 or c < 0 or r == ROWS or c == COLS or
- grid2[r][c] == 0 or (r, c) in visit):
- return True
-
- visit.add((r, c))
- res = True
- if grid1[r][c] == 0:
- res = False
-
- res = dfs(r - 1, c) and res
- res = dfs(r + 1, c) and res
- res = dfs(r, c - 1) and res
- res = dfs(r, c + 1) and res
- return res
-
- count = 0
- for r in range(ROWS):
- for c in range(COLS):
- if grid2[r][c] and (r, c) not in visit and dfs(r, c):
- count += 1
- return count
diff --git a/191-Number-of-1-Bits.py b/191-Number-of-1-Bits.py
deleted file mode 100644
index 9a61e7784..000000000
--- a/191-Number-of-1-Bits.py
+++ /dev/null
@@ -1,7 +0,0 @@
-class Solution:
- def hammingWeight(self, n: int) -> int:
- res = 0
- while n:
- n &= (n - 1)
- res += 1
- return res
diff --git a/198-House-Robber.py b/198-House-Robber.py
deleted file mode 100644
index d6f380340..000000000
--- a/198-House-Robber.py
+++ /dev/null
@@ -1,9 +0,0 @@
-class Solution:
- def rob(self, nums: List[int]) -> int:
- rob1, rob2 = 0, 0
-
- for n in nums:
- temp = max(n + rob1, rob2)
- rob1 = rob2
- rob2 = temp
- return rob2
diff --git a/199-Binary-Tree-Right-Side-View.py b/199-Binary-Tree-Right-Side-View.py
deleted file mode 100644
index 11040e880..000000000
--- a/199-Binary-Tree-Right-Side-View.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# Definition for a binary tree node.
-# class TreeNode:
-# def __init__(self, val=0, left=None, right=None):
-# self.val = val
-# self.left = left
-# self.right = right
-class Solution:
- def rightSideView(self, root: TreeNode) -> List[int]:
- res = []
- q = collections.deque([root])
-
- while q:
- rightSide = None
- qLen = len(q)
-
- for i in range(qLen):
- node = q.popleft()
- if node:
- rightSide = node
- q.append(node.left)
- q.append(node.right)
- if rightSide:
- res.append(rightSide.val)
- return res
diff --git a/2-Add-Two-Numbers.py b/2-Add-Two-Numbers.py
deleted file mode 100644
index 63f6ed14a..000000000
--- a/2-Add-Two-Numbers.py
+++ /dev/null
@@ -1,27 +0,0 @@
-# Definition for singly-linked list.
-# class ListNode:
-# def __init__(self, val=0, next=None):
-# self.val = val
-# self.next = next
-class Solution:
- def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
- dummy = ListNode()
- cur = dummy
-
- carry = 0
- while l1 or l2 or carry:
- v1 = l1.val if l1 else 0
- v2 = l2.val if l2 else 0
-
- # new digit
- val = v1 + v2 + carry
- carry = val // 10
- val = val % 10
- cur.next = ListNode(val)
-
- # update ptrs
- cur = cur.next
- l1 = l1.next if l1 else None
- l2 = l2.next if l2 else None
-
- return dummy.next
diff --git a/20-Valid-Parentheses.py b/20-Valid-Parentheses.py
deleted file mode 100644
index 6bb09f9a7..000000000
--- a/20-Valid-Parentheses.py
+++ /dev/null
@@ -1,14 +0,0 @@
-class Solution:
- def isValid(self, s: str) -> bool:
- Map = { ")":"(", "]":"[", "}":"{" }
- stack = []
-
- for c in s:
- if c not in Map:
- stack.append(c)
- continue
- if not stack or stack[-1] != Map[c]:
- return False
- stack.pop()
-
- return not stack
diff --git a/200-Number-of-Islands.py b/200-Number-of-Islands.py
deleted file mode 100644
index 83c1e3f07..000000000
--- a/200-Number-of-Islands.py
+++ /dev/null
@@ -1,28 +0,0 @@
-class Solution:
- def numIslands(self, grid: List[List[str]]) -> int:
- if not grid or not grid[0]:
- return 0
-
- islands = 0
- q = collections.deque()
- visit = set()
- rows, cols = len(grid), len(grid[0])
-
- def dfs(r, c):
- if (r not in range(rows) or
- c not in range(cols) or
- grid[r][c] == "0" or
- (r, c) in visit):
- return
-
- visit.add((r, c))
- directions = [[0, 1], [0, -1], [1, 0], [-1, 0]]
- for dr, dc in directions:
- dfs(r + dr, c + dc)
-
- for r in range(rows):
- for c in range(cols):
- if grid[r][c] == "1" and (r, c) not in visit:
- islands += 1
- dfs(r, c)
- return islands
diff --git a/2013-Detect-Squares.py b/2013-Detect-Squares.py
deleted file mode 100644
index 82f16dc9b..000000000
--- a/2013-Detect-Squares.py
+++ /dev/null
@@ -1,19 +0,0 @@
-
-class DetectSquares:
-
- def __init__(self):
- self.ptsCount = defaultdict(int)
- self.pts = []
-
- def add(self, point: List[int]) -> None:
- self.ptsCount[tuple(point)] += 1
- self.pts.append(point)
-
- def count(self, point: List[int]) -> int:
- res = 0
- px, py = point
- for x, y in self.pts:
- if (abs(py - y) != abs(px - x)) or x == px or y == py:
- continue
- res += self.ptsCount[(x, py)] * self.ptsCount[(px, y)]
- return res
diff --git a/202-Happy-Number.py b/202-Happy-Number.py
deleted file mode 100644
index 3264c91d3..000000000
--- a/202-Happy-Number.py
+++ /dev/null
@@ -1,17 +0,0 @@
-class Solution:
- def isHappy(self, n: int) -> bool:
- slow, fast = n, self.sumSquareDigits(n)
-
- while slow != fast:
- fast = self.sumSquareDigits(fast)
- fast = self.sumSquareDigits(fast)
- slow = self.sumSquareDigits(slow)
-
- return True if fast == 1 else False
-
- def sumSquareDigits(self, n):
- output = 0
- while n:
- output += (n % 10) ** 2
- n = n // 10
- return output
diff --git a/206-Reverse-Linked-List.py b/206-Reverse-Linked-List.py
deleted file mode 100644
index a1f36aeee..000000000
--- a/206-Reverse-Linked-List.py
+++ /dev/null
@@ -1,16 +0,0 @@
-# Definition for singly-linked list.
-# class ListNode:
-# def __init__(self, x):
-# self.val = x
-# self.next = None
-
-class Solution:
- def reverseList(self, head: ListNode) -> ListNode:
- prev, curr = None, head
-
- while curr:
- temp = curr.next
- curr.next = prev
- prev = curr
- curr = temp
- return prev
diff --git a/207-Course-Schedule.py b/207-Course-Schedule.py
deleted file mode 100644
index 26f56d773..000000000
--- a/207-Course-Schedule.py
+++ /dev/null
@@ -1,26 +0,0 @@
-class Solution:
- def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool:
- # dfs
- preMap = { i:[] for i in range(numCourses)}
-
- # map each course to : prereq list
- for crs, pre in prerequisites:
- preMap[crs].append(pre)
-
- visiting = set()
- def dfs(crs):
- if crs in visiting:
- return False
- if preMap[crs] == []:
- return True
-
- visiting.add(crs)
- for pre in preMap[crs]:
- if not dfs(pre): return False
- visiting.remove(crs)
- preMap[crs] = []
- return True
-
- for c in range(numCourses):
- if not dfs(c): return False
- return True
diff --git a/208-Implement-Trie.py b/208-Implement-Trie.py
deleted file mode 100644
index 8ab6ec933..000000000
--- a/208-Implement-Trie.py
+++ /dev/null
@@ -1,49 +0,0 @@
-class TrieNode:
- def __init__(self):
- self.children = [None] * 26
- self.end = False
-
-class Trie:
-
- def __init__(self):
- """
- Initialize your data structure here.
- """
- self.root = TrieNode()
-
-
- def insert(self, word: str) -> None:
- """
- Inserts a word into the trie.
- """
- curr = self.root
- for c in word:
- i = ord(c)-ord("a")
- if curr.children[i] == None:
- curr.children[i] = TrieNode()
- curr = curr.children[i]
- curr.end = True
-
- def search(self, word: str) -> bool:
- """
- Returns if the word is in the trie.
- """
- curr = self.root
- for c in word:
- i = ord(c)-ord("a")
- if curr.children[i] == None:
- return False
- curr = curr.children[i]
- return curr.end
-
- def startsWith(self, prefix: str) -> bool:
- """
- Returns if there is any word in the trie that starts with the given prefix.
- """
- curr = self.root
- for c in prefix:
- i = ord(c)-ord("a")
- if curr.children[i] == None:
- return False
- curr = curr.children[i]
- return True
diff --git a/21-Merge-Two-Sorted-Lists.py b/21-Merge-Two-Sorted-Lists.py
deleted file mode 100644
index eb69a1c41..000000000
--- a/21-Merge-Two-Sorted-Lists.py
+++ /dev/null
@@ -1,25 +0,0 @@
-# Definition for singly-linked list.
-# class ListNode:
-# def __init__(self, val=0, next=None):
-# self.val = val
-# self.next = next
-class Solution:
- def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
- dummy = ListNode()
- tail = dummy
-
- while l1 and l2:
- if l1.val < l2.val:
- tail.next = l1
- l1 = l1.next
- else:
- tail.next = l2
- l2 = l2.next
- tail = tail.next
-
- if l1:
- tail.next = l1
- elif l2:
- tail.next = l2
-
- return dummy.next
diff --git a/210-Course-Schedule-II.py b/210-Course-Schedule-II.py
deleted file mode 100644
index 5c52edf67..000000000
--- a/210-Course-Schedule-II.py
+++ /dev/null
@@ -1,27 +0,0 @@
-class Solution:
- def findOrder(self, numCourses: int, prerequisites: List[List[int]]) -> List[int]:
- prereq = { c:[] for c in range(numCourses) }
- for crs, pre in prerequisites:
- prereq[crs].append(pre)
-
- output = []
- visit, cycle = set(), set()
- def dfs(crs):
- if crs in cycle:
- return False
- if crs in visit:
- return True
-
- cycle.add(crs)
- for pre in prereq[crs]:
- if dfs(pre) == False:
- return False
- cycle.remove(crs)
- visit.add(crs)
- output.append(crs)
- return True
-
- for c in range(numCourses):
- if dfs(c) == False:
- return []
- return output
diff --git a/211-Design-Add-and-Search-Words-Data-Structure.py b/211-Design-Add-and-Search-Words-Data-Structure.py
deleted file mode 100644
index a55cb042e..000000000
--- a/211-Design-Add-and-Search-Words-Data-Structure.py
+++ /dev/null
@@ -1,35 +0,0 @@
-class TrieNode:
- def __init__(self):
- self.children = {} # a : TrieNode
- self.word = False
-
-class WordDictionary:
- def __init__(self):
- self.root = TrieNode()
-
- def addWord(self, word: str) -> None:
- cur = self.root
- for c in word:
- if c not in cur.children:
- cur.children[c] = TrieNode()
- cur = cur.children[c]
- cur.word = True
-
- def search(self, word: str) -> bool:
- def dfs(j, root):
- cur = root
-
- for i in range(j, len(word)):
- c = word[i]
- if c == ".":
- for child in cur.children.values():
- if dfs(i + 1, child):
- return True
- return False
- else:
- if c not in cur.children:
- return False
- cur = cur.children[c]
- return cur.word
-
- return dfs(0, self.root)
diff --git a/212-Word-Search-II.py b/212-Word-Search-II.py
deleted file mode 100644
index 476ffbd32..000000000
--- a/212-Word-Search-II.py
+++ /dev/null
@@ -1,46 +0,0 @@
-class TrieNode:
- def __init__(self):
- self.children = {}
- self.isWord = False
-
- def addWord(self, word):
- cur = self
- for c in word:
- if c not in cur.children:
- cur.children[c] = TrieNode()
- cur = cur.children[c]
- cur.isWord = True
-
-
-class Solution:
- def findWords(self, board: List[List[str]], words: List[str]) -> List[str]:
- root = TrieNode()
- for w in words:
- root.addWord(w)
-
- ROWS, COLS = len(board), len(board[0])
- res, visit = set(), set()
-
- def dfs(r, c, node, word):
- if (r < 0 or c < 0 or
- r == ROWS or c == COLS or
- board[r][c] not in node.children or (r, c) in visit):
- return
-
- visit.add((r, c))
- node = node.children[board[r][c]]
- word += board[r][c]
- if node.isWord:
- res.add(word)
-
- dfs(r + 1, c, node, word)
- dfs(r - 1, c, node, word)
- dfs(r, c + 1, node, word)
- dfs(r, c - 1, node, word)
- visit.remove((r, c))
-
- for r in range(ROWS):
- for c in range(COLS):
- dfs(r, c, root, "")
-
- return list(res)
diff --git a/213-House-Robber-II.py b/213-House-Robber-II.py
deleted file mode 100644
index e03cef8ac..000000000
--- a/213-House-Robber-II.py
+++ /dev/null
@@ -1,12 +0,0 @@
-class Solution:
- def rob(self, nums: List[int]) -> int:
- return max(nums[0], self.helper(nums[1:]), self.helper(nums[:-1]))
-
- def helper(self, nums):
- rob1, rob2 = 0, 0
-
- for n in nums:
- newRob = max(rob1 + n, rob2)
- rob1 = rob2
- rob2 = newRob
- return rob2
diff --git a/215-Kth-Largest-Element-in-an-Array.py b/215-Kth-Largest-Element-in-an-Array.py
deleted file mode 100644
index 58221e21a..000000000
--- a/215-Kth-Largest-Element-in-an-Array.py
+++ /dev/null
@@ -1,20 +0,0 @@
-class Solution:
- def findKthLargest(self, nums: List[int], k: int) -> int:
- nums.sort()
- return nums[len(nums) - k]
-
- k = len(nums) - k
- def quickSelect(l, r):
- if l == r: return nums[l]
-
- pivot, p = nums[r], l
- for i in range(l, r):
- if nums[i] <= pivot:
- nums[p], nums[i] = nums[i], nums[p]
- p += 1
- nums[p], nums[r] = nums[r], nums[p]
-
- if p > k: return quickSelect(l, p - 1)
- elif p < k: return quickSelect(p + 1, r)
- else: return nums[p]
- return quickSelect(0, len(nums) - 1)
diff --git a/217-Contains-Duplicate.py b/217-Contains-Duplicate.py
deleted file mode 100644
index 344305a26..000000000
--- a/217-Contains-Duplicate.py
+++ /dev/null
@@ -1,9 +0,0 @@
-class Solution:
- def containsDuplicate(self, nums: List[int]) -> bool:
- hashset = set()
-
- for n in nums:
- if n in hashset:
- return True
- hashset.add(n)
- return False
diff --git a/22-Generate-Parentheses.py b/22-Generate-Parentheses.py
deleted file mode 100644
index 82e2e7e26..000000000
--- a/22-Generate-Parentheses.py
+++ /dev/null
@@ -1,21 +0,0 @@
-class Solution:
- def generateParenthesis(self, n: int) -> List[str]:
- stack = []
- res = []
-
- def backtrack(openN, closedN):
- if openN == closedN == n:
- res.append("".join(stack))
- return
-
- if openN < n:
- stack.append("(")
- backtrack(openN + 1, closedN)
- stack.pop()
- if closedN < openN:
- stack.append(")")
- backtrack(openN, closedN + 1)
- stack.pop()
-
- backtrack(0, 0)
- return res
diff --git a/221-Maximal-Square.py b/221-Maximal-Square.py
deleted file mode 100644
index 944b21965..000000000
--- a/221-Maximal-Square.py
+++ /dev/null
@@ -1,20 +0,0 @@
-class Solution:
- def maximalSquare(self, matrix: List[List[str]]) -> int:
- ROWS, COLS = len(matrix), len(matrix[0])
- cache = {} # map each (r, c) -> maxLength of square
-
- def helper(r, c):
- if r >= ROWS or c >= COLS:
- return 0
-
- if (r, c) not in cache:
- down = helper(r + 1, c)
- right = helper(r, c + 1)
- diag = helper(r + 1, c + 1)
-
- cache[(r, c)] = 0
- if matrix[r][c] == "1":
- cache[(r, c)] = 1 + min(down, right, diag)
- return cache[(r, c)]
- helper(0, 0)
- return max(cache.values()) ** 2
diff --git a/226-Invert-Binary-Tree.py b/226-Invert-Binary-Tree.py
deleted file mode 100644
index 36de77ef4..000000000
--- a/226-Invert-Binary-Tree.py
+++ /dev/null
@@ -1,19 +0,0 @@
-# Definition for a binary tree node.
-# class TreeNode:
-# def __init__(self, val=0, left=None, right=None):
-# self.val = val
-# self.left = left
-# self.right = right
-class Solution:
- def invertTree(self, root: TreeNode) -> TreeNode:
- if not root:
- return None
-
- # swap the children
- tmp = root.left
- root.left = root.right
- root.right = tmp
-
- self.invertTree(root.left)
- self.invertTree(root.right)
- return root
diff --git a/23-Merge-K-Sorted-Lists.py b/23-Merge-K-Sorted-Lists.py
deleted file mode 100644
index 54cabf592..000000000
--- a/23-Merge-K-Sorted-Lists.py
+++ /dev/null
@@ -1,36 +0,0 @@
-# Definition for singly-linked list.
-# class ListNode:
-# def __init__(self, val=0, next=None):
-# self.val = val
-# self.next = next
-class Solution:
- def mergeKLists(self, lists: List[ListNode]) -> ListNode:
- if not lists or len(lists) == 0:
- return None
-
- while len(lists) > 1:
- mergedLists = []
- for i in range(0, len(lists), 2):
- l1 = lists[i]
- l2 = lists[i + 1] if (i + 1) < len(lists) else None
- mergedLists.append(self.mergeList(l1, l2))
- lists = mergedLists
- return lists[0]
-
- def mergeList(self, l1, l2):
- dummy = ListNode()
- tail = dummy
-
- while l1 and l2:
- if l1.val < l2.val:
- tail.next = l1
- l1 = l1.next
- else:
- tail.next = l2
- l2 = l2.next
- tail = tail.next
- if l1:
- tail.next = l1
- if l2:
- tail.next = l2
- return dummy.next
diff --git a/230-Kth-Smallest-Element-in-a-BST.py b/230-Kth-Smallest-Element-in-a-BST.py
deleted file mode 100644
index f79a0be6d..000000000
--- a/230-Kth-Smallest-Element-in-a-BST.py
+++ /dev/null
@@ -1,21 +0,0 @@
-# Definition for a binary tree node.
-# class TreeNode:
-# def __init__(self, x):
-# self.val = x
-# self.left = None
-# self.right = None
-
-class Solution:
- def kthSmallest(self, root: TreeNode, k: int) -> int:
- stack = []
- curr = root
-
- while stack or curr:
- while curr:
- stack.append(curr)
- curr = curr.left
- curr = stack.pop()
- k -= 1
- if k == 0:
- return curr.val
- curr = curr.right
diff --git a/236-Lowest-Common-Ancestor-of-a-Binary-Tree.py b/236-Lowest-Common-Ancestor-of-a-Binary-Tree.py
deleted file mode 100644
index 1c33c28b0..000000000
--- a/236-Lowest-Common-Ancestor-of-a-Binary-Tree.py
+++ /dev/null
@@ -1,29 +0,0 @@
-# Definition for a binary tree node.
-# class TreeNode:
-# def __init__(self, x):
-# self.val = x
-# self.left = None
-# self.right = None
-
-class Solution:
- res = None
- def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':
- if not root or not p or not q: return None
-
- def search(root, p, q):
- if not root: return False
- mid = left = right = False
- if root.val == p.val or root.val == q.val:
- mid = True
-
- left = search(root.left, p, q)
- right = search(root.right, p, q)
- if mid:
- if left or right:
- self.res = root
- elif left and right:
- self.res = root
- return mid or left or right
-
- search(root, p, q)
- return self.res
diff --git a/238-Product-of-array-except-self.py b/238-Product-of-array-except-self.py
deleted file mode 100644
index 77ccdf892..000000000
--- a/238-Product-of-array-except-self.py
+++ /dev/null
@@ -1,14 +0,0 @@
-class Solution:
- def productExceptSelf(self, nums: List[int]) -> List[int]:
- res = [1] * (len(nums))
-
- prefix = 1
- for i in range(len(nums)):
- res[i] = prefix
- prefix *= nums[i]
- postfix = 1
- for i in range(len(nums) - 1, -1, -1):
- res[i] *= postfix
- postfix *= nums[i]
- return res
-
diff --git a/239-Sliding-Window-Maximum.py b/239-Sliding-Window-Maximum.py
deleted file mode 100644
index d78266eb6..000000000
--- a/239-Sliding-Window-Maximum.py
+++ /dev/null
@@ -1,19 +0,0 @@
-class Solution:
- def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
- indexQ = deque()
- valQ = deque()
-
- res = []
- for i, n in enumerate(nums):
- while valQ and n > valQ[-1]:
- valQ.pop()
- indexQ.pop()
- valQ.append(n)
- indexQ.append(i)
-
- while i - indexQ[0] + 1 > k:
- valQ.popleft()
- indexQ.popleft()
- if i + 1 >= k:
- res.append(valQ[0])
- return res
diff --git a/24-Swap-Nodes-in-Pairs.py b/24-Swap-Nodes-in-Pairs.py
deleted file mode 100644
index 5781a78f3..000000000
--- a/24-Swap-Nodes-in-Pairs.py
+++ /dev/null
@@ -1,25 +0,0 @@
-# Definition for singly-linked list.
-# class ListNode:
-# def __init__(self, val=0, next=None):
-# self.val = val
-# self.next = next
-class Solution:
- def swapPairs(self, head: ListNode) -> ListNode:
- dummy = ListNode(0, head)
- prev, curr = dummy, head
-
- while curr and curr.next:
- # save ptrs
- nxtPair = curr.next.next
- second = curr.next
-
- # reverse this pair
- second.next = curr
- curr.next = nxtPair
- prev.next = second
-
- # update ptrs
- prev = curr
- curr = nxtPair
-
- return dummy.next
diff --git a/242-Valid-Anagrams.py b/242-Valid-Anagrams.py
deleted file mode 100644
index ffb09d661..000000000
--- a/242-Valid-Anagrams.py
+++ /dev/null
@@ -1,14 +0,0 @@
-class Solution:
- def isAnagram(self, s: str, t: str) -> bool:
- if len(s) != len(t):
- return False
-
- countS, countT = {}, {}
-
- for i in range(len(s)):
- countS[s[i]] = 1 + countS.get(s[i], 0)
- countT[t[i]] = 1 + countT.get(t[i], 0)
- for c in countS:
- if countS[c] != countT.get(c, 0):
- return False
- return True
diff --git a/25-Reverse-Nodes-in-K-Group.py b/25-Reverse-Nodes-in-K-Group.py
deleted file mode 100644
index 0add4f17d..000000000
--- a/25-Reverse-Nodes-in-K-Group.py
+++ /dev/null
@@ -1,29 +0,0 @@
-class Solution:
- def reverseKGroup(self, head: ListNode, k: int) -> ListNode:
- dummy = ListNode(0, head)
- groupPrev = dummy
-
- while True:
- kth = self.getKth(groupPrev, k)
- if not kth:
- break
- groupNext = kth.next
-
- # reverse group
- prev, curr = kth.next, groupPrev.next
- while curr != groupNext:
- tmp = curr.next
- curr.next = prev
- prev = curr
- curr = tmp
-
- tmp = groupPrev.next
- groupPrev.next = kth
- groupPrev = tmp
- return dummy.next
-
- def getKth(self, curr, k):
- while curr and k > 0:
- curr = curr.next
- k -= 1
- return curr
diff --git a/252-Meeting-Rooms.py b/252-Meeting-Rooms.py
deleted file mode 100644
index 85b827b8b..000000000
--- a/252-Meeting-Rooms.py
+++ /dev/null
@@ -1,15 +0,0 @@
-class Solution:
- """
- @param intervals: an array of meeting time intervals
- @return: if a person could attend all meetings
- """
- def canAttendMeetings(self, intervals):
- intervals.sort(key = lambda i : i.start)
-
- for i in range(1, len(intervals)):
- i1 = intervals[i - 1]
- i2 = intervals[i]
-
- if i1.end > i2.start:
- return False
- return True
diff --git a/253-Meeting-Rooms-ii.py b/253-Meeting-Rooms-ii.py
deleted file mode 100644
index f58fb7a20..000000000
--- a/253-Meeting-Rooms-ii.py
+++ /dev/null
@@ -1,20 +0,0 @@
-class Solution:
- """
- @param intervals: an array of meeting time intervals
- @return: the minimum number of conference rooms required
- """
- def minMeetingRooms(self, intervals):
- start = sorted([i.start for i in intervals])
- end = sorted([i.end for i in intervals])
-
- res, count = 0, 0
- s, e = 0, 0
- while s < len(intervals):
- if start[s] < end[e]:
- s += 1
- count += 1
- else:
- e += 1
- count -= 1
- res = max(res, count)
- return res
diff --git a/261-Graph-Valid-Tree.py b/261-Graph-Valid-Tree.py
deleted file mode 100644
index 0f5e5f36b..000000000
--- a/261-Graph-Valid-Tree.py
+++ /dev/null
@@ -1,29 +0,0 @@
-# Problem is free on Lintcode
-class Solution:
- """
- @param n: An integer
- @param edges: a list of undirected edges
- @return: true if it's a valid tree, or false
- """
- def validTree(self, n, edges):
- if not n:
- return True
- adj = { i:[] for i in range(n) }
- for n1, n2 in edges:
- adj[n1].append(n2)
- adj[n2].append(n1)
-
- visit = set()
- def dfs(i, prev):
- if i in visit:
- return False
-
- visit.add(i)
- for j in adj[i]:
- if j == prev:
- continue
- if not dfs(j, i):
- return False
- return True
-
- return dfs(0, -1) and n == len(visit)
diff --git a/268-Missing-Number.py b/268-Missing-Number.py
deleted file mode 100644
index 1e90165d8..000000000
--- a/268-Missing-Number.py
+++ /dev/null
@@ -1,7 +0,0 @@
-class Solution:
- def missingNumber(self, nums: List[int]) -> int:
- res = len(nums)
-
- for i in range(len(nums)):
- res += (i - nums[i])
- return res
diff --git a/271-Encode-and-Decode-Strings.py b/271-Encode-and-Decode-Strings.py
deleted file mode 100644
index b96c9a028..000000000
--- a/271-Encode-and-Decode-Strings.py
+++ /dev/null
@@ -1,26 +0,0 @@
-class Solution:
- """
- @param: strs: a list of strings
- @return: encodes a list of strings to a single string.
- """
- def encode(self, strs):
- res = ""
- for s in strs:
- res += str(len(s)) + "#" + s
- return res
-
- """
- @param: str: A string
- @return: dcodes a single string to a list of strings
- """
- def decode(self, str):
- res, i = [], 0
-
- while i < len(str):
- j = i
- while str[j] != "#":
- j += 1
- length = int(str[i:j])
- res.append(str[j + 1 : j + 1 + length])
- i = j + 1 + length
- return res
diff --git a/28-Implement-strStr.py b/28-Implement-strStr.py
deleted file mode 100644
index e43bb4564..000000000
--- a/28-Implement-strStr.py
+++ /dev/null
@@ -1,30 +0,0 @@
-class Solution:
- def strStr(self, haystack: str, needle: str) -> int:
- if needle == "": return 0
- lps = [0] * len(needle)
-
- prevLPS, i = 0, 1
- while i < len(needle):
- if needle[i] == needle[prevLPS]:
- lps[i] = prevLPS + 1
- prevLPS += 1
- i += 1
- elif prevLPS == 0:
- lps[i] = 0
- i += 1
- else:
- prevLPS = lps[prevLPS - 1]
-
- i = 0 # ptr for haystack
- j = 0 # ptr for needle
- while i < len(haystack):
- if haystack[i] == needle[j]:
- i, j = i + 1, j + 1
- else:
- if j == 0:
- i += 1
- else:
- j = lps[j - 1]
- if j == len(needle):
- return i - len(needle)
- return -1
diff --git a/286-Walls-and-Gates.py b/286-Walls-and-Gates.py
deleted file mode 100644
index 785df81f7..000000000
--- a/286-Walls-and-Gates.py
+++ /dev/null
@@ -1,27 +0,0 @@
-class Solution:
- """
- @param rooms: m x n 2D grid
- @return: nothing
- """
- def walls_and_gates(self, rooms: List[List[int]]):
- ROWS, COLS = len(rooms), len(rooms[0])
- visit = set()
- q = deque()
-
- def addRooms(r, c):
- if (min(r, c) < 0 or r == ROWS or c == COLS or
- (r, c) in visit or rooms[r][c] == -1):
- return
- visit.add((r, c))
- q.append([r, c])
-
- dist = 0
- while q:
- for i in range(len(q)):
- r, c = q.popleft()
- rooms[r][c] = dist
- addRooms(r + 1, c)
- addRooms(r - 1, c)
- addRooms(r, c + 1)
- addRooms(r, c - 1)
- dist += 1
diff --git a/287-Find-The-Duplicate-Number.py b/287-Find-The-Duplicate-Number.py
deleted file mode 100644
index cf498bf8b..000000000
--- a/287-Find-The-Duplicate-Number.py
+++ /dev/null
@@ -1,15 +0,0 @@
-class Solution:
- def findDuplicate(self, nums: List[int]) -> int:
- slow, fast = 0, 0
- while True:
- slow = nums[slow]
- fast = nums[nums[fast]]
- if slow == fast:
- break
-
- slow2 = 0
- while True:
- slow = nums[slow]
- slow2 = nums[slow2]
- if slow == slow2:
- return slow
diff --git a/295-Find-Median-from-Data-Stream.py b/295-Find-Median-from-Data-Stream.py
deleted file mode 100644
index d2a5cc404..000000000
--- a/295-Find-Median-from-Data-Stream.py
+++ /dev/null
@@ -1,30 +0,0 @@
-class MedianFinder:
-
- def __init__(self):
- """
- initialize your data structure here.
- """
- # two heaps, large, small, minheap, maxheap
- # heaps should be equal size
- self.small, self.large = [], [] # maxHeap, minHeap (python default)
-
- def addNum(self, num: int) -> None:
- heapq.heappush(self.small, -1 * num)
-
- if (self.small and self.large and (-1 * self.small[0]) > self.large[0]):
- val = -1 * heapq.heappop(self.small)
- heapq.heappush(self.large, val)
-
- if len(self.small) > len(self.large) + 1:
- val = -1 * heapq.heappop(self.small)
- heapq.heappush(self.large, val)
- if len(self.large) > len(self.small) + 1:
- val = heapq.heappop(self.large)
- heapq.heappush(self.small, -1 * val)
-
- def findMedian(self) -> float:
- if len(self.small) > len(self.large):
- return -1 * self.small[0]
- elif len(self.large) > len(self.small):
- return self.large[0]
- return (-1 * self.small[0] + self.large[0]) / 2
diff --git a/297-Serialize-and-Deserialize-Binary-Tree.py b/297-Serialize-and-Deserialize-Binary-Tree.py
deleted file mode 100644
index 764c08422..000000000
--- a/297-Serialize-and-Deserialize-Binary-Tree.py
+++ /dev/null
@@ -1,36 +0,0 @@
-# Definition for a binary tree node.
-# class TreeNode(object):
-# def __init__(self, x):
-# self.val = x
-# self.left = None
-# self.right = None
-
-class Codec:
-
- def serialize(self, root):
- res = []
-
- def dfs(node):
- if not node:
- res.append("N")
- return
- res.append(str(node.val))
- dfs(node.left)
- dfs(node.right)
- dfs(root)
- return ",".join(res)
-
- def deserialize(self, data):
- vals = data.split(",")
- self.i = 0
-
- def dfs():
- if vals[self.i] == "N":
- self.i += 1
- return None
- node = TreeNode(int(vals[self.i]))
- self.i += 1
- node.left = dfs()
- node.right = dfs()
- return node
- return dfs()
diff --git a/3-Longest-Substring-Without-Repeating-Characters.py b/3-Longest-Substring-Without-Repeating-Characters.py
deleted file mode 100644
index e37d07824..000000000
--- a/3-Longest-Substring-Without-Repeating-Characters.py
+++ /dev/null
@@ -1,13 +0,0 @@
-class Solution:
- def lengthOfLongestSubstring(self, s: str) -> int:
- charSet = set()
- l = 0
- res = 0
-
- for r in range(len(s)):
- while s[r] in charSet:
- charSet.remove(s[l])
- l += 1
- charSet.add(s[r])
- res = max(res, r - l + 1)
- return res
diff --git a/300-Longest-Increasing-Subsequence.py b/300-Longest-Increasing-Subsequence.py
deleted file mode 100644
index 8799e78b5..000000000
--- a/300-Longest-Increasing-Subsequence.py
+++ /dev/null
@@ -1,9 +0,0 @@
-class Solution:
- def lengthOfLIS(self, nums: List[int]) -> int:
- LIS = [1] * len(nums)
-
- for i in range(len(nums) - 1, -1, -1):
- for j in range(i + 1, len(nums)):
- if nums[i] < nums[j]:
- LIS[i] = max(LIS[i], 1 + LIS[j])
- return max(LIS)
diff --git a/309-Best-Time-To-Buy-and-Sell-Stock-With-Cooldown.py b/309-Best-Time-To-Buy-and-Sell-Stock-With-Cooldown.py
deleted file mode 100644
index 582475cb1..000000000
--- a/309-Best-Time-To-Buy-and-Sell-Stock-With-Cooldown.py
+++ /dev/null
@@ -1,24 +0,0 @@
-class Solution:
- def maxProfit(self, prices: List[int]) -> int:
- # State: Buying or Selling?
- # If Buy -> i + 1
- # If Sell -> i + 2
-
- dp = {} # key=(i, buying) val=max_profit
-
- def dfs(i, buying):
- if i >= len(prices):
- return 0
- if (i, buying) in dp:
- return dp[(i, buying)]
-
- cooldown = dfs(i + 1, buying)
- if buying:
- buy = dfs(i + 1, not buying) - prices[i]
- dp[(i, buying)] = max(buy, cooldown)
- else:
- sell = dfs(i + 2, not buying) + prices[i]
- dp[(i, buying)] = max(sell, cooldown)
- return dp[(i, buying)]
-
- return dfs(0, True)
diff --git a/312-Burst-Balloons.py b/312-Burst-Balloons.py
deleted file mode 100644
index f3199e8ac..000000000
--- a/312-Burst-Balloons.py
+++ /dev/null
@@ -1,13 +0,0 @@
-class Solution:
- def maxCoins(self, nums: List[int]) -> int:
- cache = {}
- nums = [1] + nums + [1]
-
- for offset in range(2, len(nums)):
- for left in range(len(nums) - offset):
- right = left + offset
- for pivot in range(left + 1, right):
- coins = nums[left] * nums[pivot] * nums[right]
- coins += cache.get((left, pivot), 0) + cache.get((pivot, right), 0)
- cache[(left, right)] = max(coins, cache.get((left, right), 0))
- return cache.get((0, len(nums) - 1), 0)
diff --git a/322-Coin-Change.py b/322-Coin-Change.py
deleted file mode 100644
index ef870465a..000000000
--- a/322-Coin-Change.py
+++ /dev/null
@@ -1,10 +0,0 @@
-class Solution:
- def coinChange(self, coins: List[int], amount: int) -> int:
- dp = [amount + 1] * (amount + 1)
- dp[0] = 0
-
- for a in range(1, amount + 1):
- for c in coins:
- if a - c >= 0:
- dp[a] = min(dp[a], 1 + dp[a - c])
- return dp[amount] if dp[amount] != amount + 1 else -1
diff --git a/329-Longest-Increasing-Path-in-a-Matrix.py b/329-Longest-Increasing-Path-in-a-Matrix.py
deleted file mode 100644
index bea327654..000000000
--- a/329-Longest-Increasing-Path-in-a-Matrix.py
+++ /dev/null
@@ -1,25 +0,0 @@
-class Solution:
- def longestIncreasingPath(self, matrix: List[List[int]]) -> int:
- ROWS, COLS = len(matrix), len(matrix[0])
- dp = {} # (r, c) -> LIP
-
- def dfs(r, c, prevVal):
- if (r < 0 or r == ROWS or
- c < 0 or c == COLS or
- matrix[r][c] <= prevVal):
- return 0
- if (r, c) in dp:
- return dp[(r, c)]
-
- res = 1
- res = max(res, 1 + dfs(r + 1, c, matrix[r][c]))
- res = max(res, 1 + dfs(r - 1, c, matrix[r][c]))
- res = max(res, 1 + dfs(r, c + 1, matrix[r][c]))
- res = max(res, 1 + dfs(r, c - 1, matrix[r][c]))
- dp[(r, c)] = res
- return res
-
- for r in range(ROWS):
- for c in range(COLS):
- dfs(r, c, -1)
- return max(dp.values())
diff --git a/33-Search-In-Rotated-Sorted-Array.py b/33-Search-In-Rotated-Sorted-Array.py
deleted file mode 100644
index faf1939cd..000000000
--- a/33-Search-In-Rotated-Sorted-Array.py
+++ /dev/null
@@ -1,22 +0,0 @@
-class Solution:
- def search(self, nums: List[int], target: int) -> int:
- l, r = 0, len(nums) - 1
-
- while l <= r:
- mid = (l + r) // 2
- if target == nums[mid]:
- return mid
-
- # left sorted portion
- if nums[l] <= nums[mid]:
- if target > nums[mid] or target < nums[l]:
- l = mid + 1
- else:
- r = mid - 1
- # right sorted portion
- else:
- if target < nums[mid] or target > nums[r]:
- r = mid - 1
- else:
- l = mid + 1
- return -1
diff --git a/332-Reconstruct-Itinerary.py b/332-Reconstruct-Itinerary.py
deleted file mode 100644
index 7ff52ba29..000000000
--- a/332-Reconstruct-Itinerary.py
+++ /dev/null
@@ -1,26 +0,0 @@
-class Solution:
- def findItinerary(self, tickets: List[List[str]]) -> List[str]:
- adj = { u:collections.deque() for u, v in tickets }
- res = ["JFK"]
-
- tickets.sort()
- for u, v in tickets:
- adj[u].append(v)
-
- def dfs(cur):
- if len(res) == len(tickets) + 1:
- return True
- if cur not in adj:
- return False
-
- temp = list(adj[cur])
- for v in temp:
- adj[cur].popleft()
- res.append(v)
- if dfs(v):
- return res
- res.pop()
- adj[cur].append(v)
- return False
- dfs("JFK")
- return res
diff --git a/338-Counting-Bits.py b/338-Counting-Bits.py
deleted file mode 100644
index 81e7f3655..000000000
--- a/338-Counting-Bits.py
+++ /dev/null
@@ -1,10 +0,0 @@
-class Solution:
- def countBits(self, n: int) -> List[int]:
- dp = [0] * (n + 1)
- offset = 1
-
- for i in range(1, n + 1):
- if offset * 2 == i:
- offset = i
- dp[i] = 1 + dp[i - offset]
- return dp
diff --git a/34-Find-First-and-Last-Position-of-Element-in-Sorted-Array.py b/34-Find-First-and-Last-Position-of-Element-in-Sorted-Array.py
deleted file mode 100644
index ca3a84f5f..000000000
--- a/34-Find-First-and-Last-Position-of-Element-in-Sorted-Array.py
+++ /dev/null
@@ -1,23 +0,0 @@
-class Solution:
- def searchRange(self, nums: List[int], target: int) -> List[int]:
- left = self.binSearch(nums, target, True)
- right = self.binSearch(nums, target, False)
- return [left, right]
-
- # leftBias=[True/False], if false, res is rightBiased
- def binSearch(self, nums, target, leftBias):
- l, r = 0, len(nums) - 1
- i = -1
- while l <= r:
- m = (l + r) // 2
- if target > nums[m]:
- l = m + 1
- elif target < nums[m]:
- r = m - 1
- else:
- i = m
- if leftBias:
- r = m - 1
- else:
- l = m + 1
- return i
diff --git a/347-Top-k-frequent-elements.py b/347-Top-k-frequent-elements.py
deleted file mode 100644
index 953241d42..000000000
--- a/347-Top-k-frequent-elements.py
+++ /dev/null
@@ -1,18 +0,0 @@
-class Solution:
- def topKFrequent(self, nums: List[int], k: int) -> List[int]:
- count = {}
- freq = [[] for i in range(len(nums) + 1)]
-
- for n in nums:
- count[n] = 1 + count.get(n, 0)
- for n, c in count.items():
- freq[c].append(n)
-
- res = []
- for i in range(len(freq) - 1, 0, -1):
- for n in freq[i]:
- res.append(n)
- if len(res) == k:
- return res
-
- # O(n)
diff --git a/355-Design-Twitter.py b/355-Design-Twitter.py
deleted file mode 100644
index 7dce41b88..000000000
--- a/355-Design-Twitter.py
+++ /dev/null
@@ -1,36 +0,0 @@
-class Twitter:
-
- def __init__(self):
- self.count = 0
- self.tweetMap = defaultdict(list) # userId -> list of [count, tweetIds]
- self.followMap = defaultdict(set) # userId -> set of followeeId
-
- def postTweet(self, userId: int, tweetId: int) -> None:
- self.tweetMap[userId].append([self.count, tweetId])
- self.count -= 1
-
- def getNewsFeed(self, userId: int) -> List[int]:
- res = []
- minHeap = []
-
- self.followMap[userId].add(userId)
- for followeeId in self.followMap[userId]:
- if followeeId in self.tweetMap:
- index = len(self.tweetMap[followeeId]) - 1
- count, tweetId = self.tweetMap[followeeId][index]
- heapq.heappush(minHeap, [count, tweetId, followeeId, index - 1])
-
- while minHeap and len(res) < 10:
- count, tweetId, followeeId, index = heapq.heappop(minHeap)
- res.append(tweetId)
- if index >= 0:
- count, tweetId = self.tweetMap[followeeId][index]
- heapq.heappush(minHeap, [count, tweetId, followeeId, index - 1])
- return res
-
- def follow(self, followerId: int, followeeId: int) -> None:
- self.followMap[followerId].add(followeeId)
-
- def unfollow(self, followerId: int, followeeId: int) -> None:
- if followeeId in self.followMap[followerId]:
- self.followMap[followerId].remove(followeeId)
diff --git a/36-Valid-Sudoku.py b/36-Valid-Sudoku.py
deleted file mode 100644
index 81821662e..000000000
--- a/36-Valid-Sudoku.py
+++ /dev/null
@@ -1,19 +0,0 @@
-class Solution:
- def isValidSudoku(self, board: List[List[str]]) -> bool:
- cols = collections.defaultdict(set)
- rows = collections.defaultdict(set)
- squares = collections.defaultdict(set) # key = (r /3, c /3)
-
- for r in range(9):
- for c in range(9):
- if board[r][c] == ".":
- continue
- if (board[r][c] in rows[r] or
- board[r][c] in cols[c] or
- board[r][c] in squares[(r // 3, c // 3)]):
- return False
- cols[c].add(board[r][c])
- rows[r].add(board[r][c])
- squares[(r // 3, c // 3)].add(board[r][c])
-
- return True
diff --git a/371-Sum-of-Two-Integers.java b/371-Sum-of-Two-Integers.java
deleted file mode 100644
index ff641469f..000000000
--- a/371-Sum-of-Two-Integers.java
+++ /dev/null
@@ -1,10 +0,0 @@
-class Solution {
- public int getSum(int a, int b) {
- while (b != 0) {
- int tmp = (a & b) << 1;
- a = (a ^ b);
- b = tmp;
- }
- return a;
- }
-}
diff --git a/371-Sum-of-Two-Integers.py b/371-Sum-of-Two-Integers.py
deleted file mode 100644
index 476bfe662..000000000
--- a/371-Sum-of-Two-Integers.py
+++ /dev/null
@@ -1,16 +0,0 @@
-class Solution:
- def getSum(self, a: int, b: int) -> int:
- def add(a, b):
- if not a or not b:
- return a or b
- return add(a^b, (a&b) << 1)
-
- if a*b < 0: # assume a < 0, b > 0
- if a > 0:
- return self.getSum(b, a)
- if add(~a, 1) == b: # -a == b
- return 0
- if add(~a, 1) < b: # -a < b
- return add(~add(add(~a, 1), add(~b, 1)),1) # -add(-a, -b)
-
- return add(a, b) # a*b >= 0 or (-a) > b > 0
diff --git a/377-Combination-Sum-IV.py b/377-Combination-Sum-IV.py
deleted file mode 100644
index 1b56bb779..000000000
--- a/377-Combination-Sum-IV.py
+++ /dev/null
@@ -1,23 +0,0 @@
-class Solution:
- def combinationSum4(self, nums: List[int], target: int) -> int:
- cache = { 0:1 }
-
- for total in range(1, target + 1):
- cache[total] = 0
- for n in nums:
- cache[total] += cache.get(total - n, 0)
- return cache[target]
-
- def dfs(total):
- if total == target:
- return 1
- if total > target:
- return 0
- if total in cache:
- return cache[total]
-
- cache[total] = 0
- for n in nums:
- cache[total] += dfs(total + n)
- return cache[total]
- return dfs(0)
diff --git a/39-Combination-Sum.py b/39-Combination-Sum.py
deleted file mode 100644
index f156c10f8..000000000
--- a/39-Combination-Sum.py
+++ /dev/null
@@ -1,18 +0,0 @@
-class Solution:
- def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
- res = []
-
- def dfs(i, cur, total):
- if total == target:
- res.append(cur.copy())
- return
- if i >= len(candidates) or total > target:
- return
-
- cur.append(candidates[i])
- dfs(i, cur, total + candidates[i])
- cur.pop()
- dfs(i + 1, cur, total)
-
- dfs(0, [], 0)
- return res
diff --git a/394-decode-string.py b/394-decode-string.py
deleted file mode 100644
index 445a81cfd..000000000
--- a/394-decode-string.py
+++ /dev/null
@@ -1,20 +0,0 @@
-class Solution:
- def decodeString(self, s: str) -> str:
- stack = []
-
- for char in s:
- if char is not "]":
- stack.append(char)
- else:
- sub_str = ""
- while stack[-1] is not "[":
- sub_str = stack.pop()+sub_str
- stack.pop()
-
- multiplier = ""
- while stack and stack[-1].isdigit():
- multiplier = stack.pop() + multiplier
-
- stack.append(int(multiplier)*sub_str)
-
- return "".join(stack)
\ No newline at end of file
diff --git a/4-median-of-two-sorted-arrays.py b/4-median-of-two-sorted-arrays.py
deleted file mode 100644
index 6ade3557b..000000000
--- a/4-median-of-two-sorted-arrays.py
+++ /dev/null
@@ -1,32 +0,0 @@
-# Time: log(min(n, m))
-
-class Solution:
- def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
- A, B = nums1, nums2
- total = len(nums1) + len(nums2)
- half = total // 2
-
- if len(B) < len(A):
- A, B = B, A
-
- l, r = 0, len(A) - 1
- while True:
- i = (l + r) // 2 # A
- j = half - i - 2 # B
-
- Aleft = A[i] if i >= 0 else float("-infinity")
- Aright = A[i + 1] if (i + 1) < len(A) else float("infinity")
- Bleft = B[j] if j >= 0 else float("-infinity")
- Bright = B[j + 1] if (j + 1) < len(B) else float("infinity")
-
- # partition is correct
- if Aleft <= Bright and Bleft <= Aright:
- # odd
- if total % 2:
- return min(Aright, Bright)
- # even
- return (max(Aleft, Bleft) + min(Aright, Bright)) / 2
- elif Aleft > Bright:
- r = i - 1
- else:
- l = i + 1
diff --git a/40-Combination-Sum-II.py b/40-Combination-Sum-II.py
deleted file mode 100644
index e85438173..000000000
--- a/40-Combination-Sum-II.py
+++ /dev/null
@@ -1,22 +0,0 @@
-class Solution:
- def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]:
- candidates.sort()
-
- res = []
- def backtrack(cur, pos, target):
- if target == 0:
- res.append(cur.copy())
- if target <= 0:
- return
-
- prev = -1
- for i in range(pos, len(candidates)):
- if candidates[i] == prev:
- continue
- cur.append(candidates[i])
- backtrack(cur, i + 1, target - candidates[i])
- cur.pop()
- prev = candidates[i]
-
- backtrack([], 0, target)
- return res
diff --git a/40-Combinations-Sum-ii.py b/40-Combinations-Sum-ii.py
deleted file mode 100644
index 27d39d393..000000000
--- a/40-Combinations-Sum-ii.py
+++ /dev/null
@@ -1,21 +0,0 @@
-class Solution:
- def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]:
- candidates.sort()
-
- res = []
- def backtrack(cur, pos, target):
- if target == 0:
- res.append(cur.copy())
- if target <= 0:
- return
-
- prev = -1
- for i in range(pos, len(candidates)):
- if candidates[i] == prev:
- continue
- cur.append(candidates[i])
- backtrack(cur, i + 1, target - candidates[i])
- cur.pop()
- prev = candidates[i]
- backtrack([], 0, target)
- return res
diff --git a/410-Split-Array-Largest-Sum.py b/410-Split-Array-Largest-Sum.py
deleted file mode 100644
index bd2f910d1..000000000
--- a/410-Split-Array-Largest-Sum.py
+++ /dev/null
@@ -1,22 +0,0 @@
-class Solution:
- def splitArray(self, nums: List[int], m: int) -> int:
- def canSplit(largest):
- subarray = 0
- curSum = 0
- for n in nums:
- curSum += n
- if curSum > largest:
- subarray += 1
- curSum = n
- return subarray + 1 <= m
-
- l, r = max(nums), sum(nums)
- res = r
- while l <= r:
- mid = l + ((r - l) // 2)
- if canSplit(mid):
- res = mid
- r = mid - 1
- else:
- l = mid + 1
- return res
diff --git a/416-Partition-Equal-Subset-Sum.py b/416-Partition-Equal-Subset-Sum.py
deleted file mode 100644
index 4d51e90ec..000000000
--- a/416-Partition-Equal-Subset-Sum.py
+++ /dev/null
@@ -1,18 +0,0 @@
-class Solution:
- def canPartition(self, nums: List[int]) -> bool:
- if sum(nums) % 2:
- return False
-
- dp = set()
- dp.add(0)
- target = sum(nums) // 2
-
- for i in range(len(nums) - 1, -1, -1):
- nextDP = set()
- for t in dp:
- if (t + nums[i]) == target:
- return True
- nextDP.add(t + nums[i])
- nextDP.add(t)
- dp = nextDP
- return True if target in dp else False
diff --git a/417-Pacific-Atlantic-Waterflow.py b/417-Pacific-Atlantic-Waterflow.py
deleted file mode 100644
index 0bb60579a..000000000
--- a/417-Pacific-Atlantic-Waterflow.py
+++ /dev/null
@@ -1,30 +0,0 @@
-class Solution:
- def pacificAtlantic(self, heights: List[List[int]]) -> List[List[int]]:
- ROWS, COLS = len(heights), len(heights[0])
- pac, atl = set(), set()
-
- def dfs(r, c, visit, prevHeight):
- if ((r, c) in visit or
- r < 0 or c < 0 or r == ROWS or c == COLS or
- heights[r][c] < prevHeight):
- return
- visit.add((r, c))
- dfs(r + 1, c, visit, heights[r][c])
- dfs(r - 1, c, visit, heights[r][c])
- dfs(r, c + 1, visit, heights[r][c])
- dfs(r, c - 1, visit, heights[r][c])
-
- for c in range(COLS):
- dfs(0, c, pac, heights[0][c])
- dfs(ROWS - 1, c, atl, heights[ROWS - 1][c])
-
- for r in range(ROWS):
- dfs(r, 0, pac, heights[r][0])
- dfs(r, COLS - 1, atl, heights[r][COLS - 1])
-
- res = []
- for r in range(ROWS):
- for c in range(COLS):
- if (r, c) in pac and (r, c) in atl:
- res.append([r, c])
- return res
diff --git a/42-Trapping-Rain-Water.py b/42-Trapping-Rain-Water.py
deleted file mode 100644
index d39a48e5b..000000000
--- a/42-Trapping-Rain-Water.py
+++ /dev/null
@@ -1,17 +0,0 @@
-class Solution:
- def trap(self, height: List[int]) -> int:
- if not height: return 0
-
- l, r = 0, len(height) - 1
- leftMax, rightMax = height[l], height[r]
- res = 0
- while l < r:
- if leftMax < rightMax:
- l += 1
- leftMax = max(leftMax, height[l])
- res += leftMax - height[l]
- else:
- r -= 1
- rightMax = max(rightMax, height[r])
- res += rightMax - height[r]
- return res
diff --git a/424-Longest-Repeating-Character-Replacement.py b/424-Longest-Repeating-Character-Replacement.py
deleted file mode 100644
index 2fdc379d5..000000000
--- a/424-Longest-Repeating-Character-Replacement.py
+++ /dev/null
@@ -1,17 +0,0 @@
-class Solution:
- def characterReplacement(self, s: str, k: int) -> int:
- count = {}
- res = 0
-
- l = 0
- maxf = 0
- for r in range(len(s)):
- count[s[r]] = 1 + count.get(s[r], 0)
- maxf = max(maxf, count[s[r]])
-
- if (r - l + 1) - maxf > k:
- count[s[l]] -= 1
- l += 1
-
- res = max(res, r - l + 1)
- return res
diff --git a/43-Multiply-Strings.py b/43-Multiply-Strings.py
deleted file mode 100644
index 1e4aaa56b..000000000
--- a/43-Multiply-Strings.py
+++ /dev/null
@@ -1,19 +0,0 @@
-class Solution:
- def multiply(self, num1: str, num2: str) -> str:
- if "0" in [num1, num2]:
- return "0"
-
- res = [0] * (len(num1) + len(num2))
- num1, num2 = num1[::-1], num2[::-1]
- for i1 in range(len(num1)):
- for i2 in range(len(num2)):
- digit = int(num1[i1]) * int(num2[i2])
- res[i1 + i2] += digit
- res[i1 + i2 + 1] += res[i1 + i2] // 10
- res[i1 + i2] = res[i1 + i2] % 10
-
- res, beg = res[::-1], 0
- while beg < len(res) and res[beg] == 0:
- beg += 1
- res = map(str, res[beg:])
- return "".join(res)
diff --git a/435-Non-Overlapping-Intervals.py b/435-Non-Overlapping-Intervals.py
deleted file mode 100644
index f9d1b71e8..000000000
--- a/435-Non-Overlapping-Intervals.py
+++ /dev/null
@@ -1,12 +0,0 @@
-class Solution:
- def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:
- intervals.sort()
- res = 0
- prevEnd = intervals[0][1]
- for start, end in intervals[1:]:
- if start >= prevEnd:
- prevEnd = end
- else:
- res += 1
- prevEnd = min(end, prevEnd)
- return res
diff --git a/448-Find-all-Numbers-Disappeared-in-an-Array.py b/448-Find-all-Numbers-Disappeared-in-an-Array.py
deleted file mode 100644
index 45db6bf9e..000000000
--- a/448-Find-all-Numbers-Disappeared-in-an-Array.py
+++ /dev/null
@@ -1,11 +0,0 @@
-class Solution:
- def findDisappearedNumbers(self, nums: List[int]) -> List[int]:
- for n in nums:
- i = abs(n) - 1
- nums[i] = -1 * abs(nums[i])
-
- res = []
- for i, n in enumerate(nums):
- if n > 0:
- res.append(i + 1)
- return res
diff --git a/45-Jump-Game-II.py b/45-Jump-Game-II.py
deleted file mode 100644
index 28a4d095f..000000000
--- a/45-Jump-Game-II.py
+++ /dev/null
@@ -1,12 +0,0 @@
-class Solution:
- def jump(self, nums: List[int]) -> int:
- l, r = 0, 0
- res = 0
- while r < (len(nums) - 1):
- maxJump = 0
- for i in range(l, r + 1):
- maxJump = max(maxJump, i + nums[i])
- l = r + 1
- r = maxJump
- res += 1
- return res
diff --git a/46-Permutations.py b/46-Permutations.py
deleted file mode 100644
index 1e263a71a..000000000
--- a/46-Permutations.py
+++ /dev/null
@@ -1,17 +0,0 @@
-class Solution:
- def permute(self, nums: List[int]) -> List[List[int]]:
- res = []
-
- # base case
- if len(nums) == 1:
- return [nums[:]] # nums[:] is a deep copy
-
- for i in range(len(nums)):
- n = nums.pop(0)
- perms = self.permute(nums)
-
- for perm in perms:
- perm.append(n)
- res.extend(perms)
- nums.append(n)
- return res
diff --git a/463-Island-Perimeter.py b/463-Island-Perimeter.py
deleted file mode 100644
index b60b55e49..000000000
--- a/463-Island-Perimeter.py
+++ /dev/null
@@ -1,22 +0,0 @@
-class Solution:
- def islandPerimeter(self, grid: List[List[int]]) -> int:
- visit = set()
-
- def dfs(i, j):
- if i >= len(grid) or j >= len(grid[0]) or \
- i < 0 or j < 0 or grid[i][j] == 0:
- return 1
- if (i, j) in visit:
- return 0
-
- visit.add((i, j))
- perim = dfs(i, j + 1)
- perim += dfs(i + 1, j)
- perim += dfs(i, j - 1)
- perim += dfs(i - 1, j)
- return perim
-
- for i in range(len(grid)):
- for j in range(len(grid[0])):
- if grid[i][j]:
- return dfs(i, j)
diff --git a/473-Matchsticks-to-Square.py b/473-Matchsticks-to-Square.py
deleted file mode 100644
index fef8256f9..000000000
--- a/473-Matchsticks-to-Square.py
+++ /dev/null
@@ -1,21 +0,0 @@
-class Solution:
- def makesquare(self, matchsticks: List[int]) -> bool:
- length = sum(matchsticks) // 4
- sides = [0] * 4
-
- if sum(matchsticks) / 4 != length:
- return False
- matchsticks.sort(reverse=True)
- def backtrack(i):
- if i == len(matchsticks):
- return True
-
- for j in range(4):
- if sides[j] + matchsticks[i] <= length:
- sides[j] += matchsticks[i]
- if backtrack(i + 1):
- return True
- sides[j] -= matchsticks[i]
- return False
-
- return backtrack(0)
diff --git a/48-Rotate-Image.py b/48-Rotate-Image.py
deleted file mode 100644
index 5300ee201..000000000
--- a/48-Rotate-Image.py
+++ /dev/null
@@ -1,26 +0,0 @@
-class Solution:
- def rotate(self, matrix: List[List[int]]) -> None:
- """
- Do not return anything, modify matrix in-place instead.
- """
- l, r = 0, len(matrix) - 1
- while l < r:
- for i in range(r - l):
- top, bottom = l, r
-
- # save the topleft
- topLeft = matrix[top][l + i]
-
- # move bottom left into top left
- matrix[top][l + i] = matrix[bottom - i][l]
-
- # move bottom right into bottom left
- matrix[bottom - i][l] = matrix[bottom][r - i]
-
- # move top right into bottom right
- matrix[bottom][r - i] = matrix[top + i][r]
-
- # move top left into top right
- matrix[top + i][r] = topLeft
- r -= 1
- l += 1
diff --git a/49-Group-Anagrams.py b/49-Group-Anagrams.py
deleted file mode 100644
index a52b995a2..000000000
--- a/49-Group-Anagrams.py
+++ /dev/null
@@ -1,10 +0,0 @@
-class Solution:
- def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
- ans = collections.defaultdict(list)
-
- for s in strs:
- count = [0] * 26
- for c in s:
- count[ord(c) - ord('a')] += 1
- ans[tuple(count)].append(s)
- return ans.values()
diff --git a/494-Target-Sum.py b/494-Target-Sum.py
deleted file mode 100644
index 6b05c6574..000000000
--- a/494-Target-Sum.py
+++ /dev/null
@@ -1,14 +0,0 @@
-class Solution:
- def findTargetSumWays(self, nums: List[int], target: int) -> int:
- dp = {} # (index, total) -> # of ways
-
- def backtrack(i, total):
- if i == len(nums):
- return 1 if total == target else 0
- if (i, total) in dp:
- return dp[(i, total)]
-
- dp[(i, total)] = (backtrack(i + 1, total + nums[i]) +
- backtrack(i + 1, total - nums[i]))
- return dp[(i, total)]
- return backtrack(0, 0)
diff --git a/5-Longest-Palindromic-Substring.py b/5-Longest-Palindromic-Substring.py
deleted file mode 100644
index 587d3d03e..000000000
--- a/5-Longest-Palindromic-Substring.py
+++ /dev/null
@@ -1,25 +0,0 @@
-class Solution:
- def longestPalindrome(self, s: str) -> str:
- res = ""
- resLen = 0
-
- for i in range(len(s)):
- # odd length
- l, r = i, i
- while l >= 0 and r < len(s) and s[l] == s[r]:
- if (r - l + 1) > resLen:
- res = s[l:r+1]
- resLen = r - l + 1
- l -= 1
- r += 1
-
- # even length
- l, r = i, i + 1
- while l >= 0 and r < len(s) and s[l] == s[r]:
- if (r - l + 1) > resLen:
- res = s[l:r+1]
- resLen = r - l + 1
- l -= 1
- r += 1
-
- return res
diff --git a/50-Pow(x, n) b/50-Pow(x, n)
deleted file mode 100644
index 857443118..000000000
--- a/50-Pow(x, n)
+++ /dev/null
@@ -1,11 +0,0 @@
-class Solution:
- def myPow(self, x: float, n: int) -> float:
- def helper(x, n):
- if x == 0: return 0
- if n == 0: return 1
-
- res = helper(x * x, n // 2)
- return x * res if n % 2 else res
-
- res = helper(x, abs(n))
- return res if n >= 0 else 1 / res
diff --git a/51-N-Queens.py b/51-N-Queens.py
deleted file mode 100644
index 9ebcfa661..000000000
--- a/51-N-Queens.py
+++ /dev/null
@@ -1,31 +0,0 @@
-class Solution:
- def solveNQueens(self, n: int) -> List[List[str]]:
- col = set()
- posDiag = set() # (r + c)
- negDiag = set() # (r - c)
-
- res = []
- board = [["."] * n for i in range(n)]
- def backtrack(r):
- if r == n:
- copy = ["".join(row) for row in board]
- res.append(copy)
- return
-
- for c in range(n):
- if c in col or (r + c) in posDiag or (r - c) in negDiag:
- continue
-
- col.add(c)
- posDiag.add(r + c)
- negDiag.add(r - c)
- board[r][c] = "Q"
-
- backtrack(r + 1)
-
- col.remove(c)
- posDiag.remove(r + c)
- negDiag.remove(r - c)
- board[r][c] = "."
- backtrack(0)
- return res
diff --git a/518-coin-change-2.py b/518-coin-change-2.py
deleted file mode 100644
index 06d2b5409..000000000
--- a/518-coin-change-2.py
+++ /dev/null
@@ -1,51 +0,0 @@
-class Solution:
- def change(self, amount: int, coins: List[int]) -> int:
- # MEMOIZATION
- # Time: O(n*m)
- # Memory: O(n*m)
- cache = {}
-
- def dfs(i, a):
- if a == amount:
- return 1
- if a > amount:
- return 0
- if i == len(coins):
- return 0
- if (i, a) in cache:
- return cache[(i, a)]
-
- cache[(i, a)] = dfs(i, a + coins[i]) + dfs(i + 1, a)
- return cache[(i, a)]
-
- return dfs(0, 0)
-
-
- # DYNAMIC PROGRAMMING
- # Time: O(n*m)
- # Memory: O(n*m)
- dp = [[0] * (len(coins) + 1) for i in range(amount + 1)]
- dp[0] = [1] * (len(coins) + 1)
- for a in range(1, amount + 1):
- for i in range(len(coins) - 1, -1, -1):
- dp[a][i] = dp[a][i + 1]
- if a - coins[i] >= 0:
- dp[a][i] += dp[a - coins[i]][i]
- return dp[amount][0]
-
-
- # DYNAMIC PROGRAMMING
- # Time: O(n*m)
- # Memory: O(n) where n = amount
- dp = [0] * (amount + 1)
- dp[0] = 1
- for i in range(len(coins) - 1, -1, -1):
- nextDP = [0] * (amount + 1)
- nextDP[0] = 1
-
- for a in range(1, amount + 1):
- nextDP[a] = dp[a]
- if a - coins[i] >= 0:
- nextDP[a] += nextDP[a - coins[i]]
- dp = nextDP
- return dp[amount]
diff --git a/53-Maximum-Subarray.py b/53-Maximum-Subarray.py
deleted file mode 100644
index 32f6defeb..000000000
--- a/53-Maximum-Subarray.py
+++ /dev/null
@@ -1,11 +0,0 @@
-class Solution:
- def maxSubArray(self, nums: List[int]) -> int:
- res = nums[0]
-
- total = 0
- for n in nums:
- total += n
- res = max(res, total)
- if total < 0:
- total = 0
- return res
diff --git a/54-Spiral-Matrix.py b/54-Spiral-Matrix.py
deleted file mode 100644
index f0226be82..000000000
--- a/54-Spiral-Matrix.py
+++ /dev/null
@@ -1,27 +0,0 @@
-class Solution:
- def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
- res = []
- left, right = 0, len(matrix[0])
- top, bottom = 0, len(matrix)
-
- while left < right and top < bottom:
- # get every i in the top row
- for i in range(left, right):
- res.append(matrix[top][i])
- top += 1
- # get every i in the right col
- for i in range(top, bottom):
- res.append(matrix[i][right - 1])
- right -= 1
- if not (left < right and top < bottom):
- break
- # get every i in the bottom row
- for i in range(right - 1, left - 1, -1):
- res.append(matrix[bottom - 1][i])
- bottom -= 1
- # get every i in the left col
- for i in range(bottom - 1, top - 1, -1):
- res.append(matrix[i][left])
- left += 1
-
- return res
diff --git a/543-Diameter-of-Binary-Tree.py b/543-Diameter-of-Binary-Tree.py
deleted file mode 100644
index 8598087b3..000000000
--- a/543-Diameter-of-Binary-Tree.py
+++ /dev/null
@@ -1,21 +0,0 @@
-# Definition for a binary tree node.
-# class TreeNode:
-# def __init__(self, val=0, left=None, right=None):
-# self.val = val
-# self.left = left
-# self.right = right
-class Solution:
- def diameterOfBinaryTree(self, root: TreeNode) -> int:
- res = [0]
-
- def dfs(root):
- if not root:
- return -1
- left = dfs(root.left)
- right = dfs(root.right)
- res[0] = max(res[0], 2 + left + right)
-
- return 1 + max(left, right)
-
- dfs(root)
- return res[0]
diff --git a/55-Jump-Game.py b/55-Jump-Game.py
deleted file mode 100644
index 67f4569e8..000000000
--- a/55-Jump-Game.py
+++ /dev/null
@@ -1,8 +0,0 @@
-class Solution:
- def canJump(self, nums: List[int]) -> bool:
- goal = len(nums) -1
-
- for i in range(len(nums) - 2, -1, -1):
- if i + nums[i] >= goal:
- goal = i
- return True if goal == 0 else False
diff --git a/56-Merge-Intervals.py b/56-Merge-Intervals.py
deleted file mode 100644
index 5b95bfe8b..000000000
--- a/56-Merge-Intervals.py
+++ /dev/null
@@ -1,14 +0,0 @@
-class Solution:
- def merge(self, intervals: List[List[int]]) -> List[List[int]]:
- intervals.sort(key = lambda pair : pair[0])
- output = [intervals[0]]
-
- for start, end in intervals:
- lastEnd = output[-1][1]
-
- if start <= lastEnd:
- # merge
- output[-1][1] = max(lastEnd, end)
- else:
- output.append([start, end])
- return output
diff --git a/567-Permutation-in-String.py b/567-Permutation-in-String.py
deleted file mode 100644
index 45093bb68..000000000
--- a/567-Permutation-in-String.py
+++ /dev/null
@@ -1,32 +0,0 @@
-class Solution:
- def checkInclusion(self, s1: str, s2: str) -> bool:
- if len(s1) > len(s2): return False
-
- s1Count, s2Count = [0] * 26, [0] * 26
- for i in range(len(s1)):
- s1Count[ord(s1[i]) - ord('a')] += 1
- s2Count[ord(s2[i]) - ord('a')] += 1
-
- matches = 0
- for i in range(26):
- matches += (1 if s1Count[i] == s2Count[i] else 0)
-
- l = 0
- for r in range(len(s1), len(s2)):
- if matches == 26: return True
-
- index = ord(s2[r]) - ord('a')
- s2Count[index] += 1
- if s1Count[index] == s2Count[index]:
- matches += 1
- elif s1Count[index] + 1 == s2Count[index]:
- matches -= 1
-
- index = ord(s2[l]) - ord('a')
- s2Count[index] -= 1
- if s1Count[index] == s2Count[index]:
- matches += 1
- elif s1Count[index] - 1 == s2Count[index]:
- matches -= 1
- l += 1
- return matches == 26
diff --git a/57-Insert-Interval.py b/57-Insert-Interval.py
deleted file mode 100644
index e454bc19f..000000000
--- a/57-Insert-Interval.py
+++ /dev/null
@@ -1,14 +0,0 @@
-class Solution:
- def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:
- res = []
-
- for i in range(len(intervals)):
- if newInterval[1] < intervals[i][0]:
- res.append(newInterval)
- return res + intervals[i:]
- elif newInterval[0] > intervals[i][1]:
- res.append(intervals[i])
- else:
- newInterval = [min(newInterval[0], intervals[i][0]), max(newInterval[1], intervals[i][1])]
- res.append(newInterval)
- return res
diff --git a/572-Subtree-of-Another-Tree.py b/572-Subtree-of-Another-Tree.py
deleted file mode 100644
index 2fcdadca8..000000000
--- a/572-Subtree-of-Another-Tree.py
+++ /dev/null
@@ -1,23 +0,0 @@
-# Definition for a binary tree node.
-# class TreeNode:
-# def __init__(self, val=0, left=None, right=None):
-# self.val = val
-# self.left = left
-# self.right = right
-class Solution:
- def isSubtree(self, s: TreeNode, t: TreeNode) -> bool:
- if not t: return True
- if not s: return False
-
- if self.sameTree(s, t):
- return True
- return (self.isSubtree(s.left, t) or
- self.isSubtree(s.right, t))
-
- def sameTree(self, s, t):
- if not s and not t:
- return True
- if s and t and s.val == t.val:
- return (self.sameTree(s.left, t.left) and
- self.sameTree(s.right, t.right))
- return False
diff --git a/617-Merge-Two-Binary-Trees.py b/617-Merge-Two-Binary-Trees.py
deleted file mode 100644
index 1c42af8c8..000000000
--- a/617-Merge-Two-Binary-Trees.py
+++ /dev/null
@@ -1,18 +0,0 @@
-# Definition for a binary tree node.
-# class TreeNode:
-# def __init__(self, val=0, left=None, right=None):
-# self.val = val
-# self.left = left
-# self.right = right
-class Solution:
- def mergeTrees(self, t1: TreeNode, t2: TreeNode) -> TreeNode:
- if not t1 and not t2:
- return None
-
- v1 = t1.val if t1 else 0
- v2 = t2.val if t2 else 0
- root = TreeNode(v1 + v2)
-
- root.left = self.mergeTrees(t1.left if t1 else None, t2.left if t2 else None)
- root.right = self.mergeTrees(t1.right if t1 else None, t2.right if t2 else None)
- return root
diff --git a/62-Unique-Paths.py b/62-Unique-Paths.py
deleted file mode 100644
index 399b27748..000000000
--- a/62-Unique-Paths.py
+++ /dev/null
@@ -1,12 +0,0 @@
-class Solution:
- def uniquePaths(self, m: int, n: int) -> int:
- row = [1] * n
-
- for i in range(m - 1):
- newRow = [1] * n
- for j in range(n - 2, -1, -1):
- newRow[j] = newRow[j + 1] + row[j]
- row = newRow
- return row[0]
-
- # O(n * m) O(n)
diff --git a/621-Task-Scheduler.py b/621-Task-Scheduler.py
deleted file mode 100644
index 2dd9a41a8..000000000
--- a/621-Task-Scheduler.py
+++ /dev/null
@@ -1,20 +0,0 @@
-class Solution:
- def leastInterval(self, tasks: List[str], n: int) -> int:
- count = Counter(tasks)
- maxHeap = [-cnt for cnt in count.values()]
- heapq.heapify(maxHeap)
-
- time = 0
- q = deque() # pairs of [-cnt, idleTime]
- while maxHeap or q:
- time += 1
-
- if not maxHeap:
- time = q[0][1]
- else:
- cnt = 1 + heapq.heappop(maxHeap)
- if cnt:
- q.append([cnt, time + n])
- if q and q[0][1] == time:
- heapq.heappush(maxHeap, q.popleft()[0])
- return time
diff --git a/647-Palindromic-Substrings.py b/647-Palindromic-Substrings.py
deleted file mode 100644
index b622cbfef..000000000
--- a/647-Palindromic-Substrings.py
+++ /dev/null
@@ -1,16 +0,0 @@
-class Solution:
- def countSubstrings(self, s: str) -> int:
- res = 0
-
- for i in range(len(s)):
- res += self.countPali(s, i, i)
- res += self.countPali(s, i, i + 1)
- return res
-
- def countPali(self, s, l, r):
- res = 0
- while l >= 0 and r < len(s) and s[l] == s[r]:
- res += 1
- l -= 1
- r += 1
- return res
diff --git a/658-Find-K-Closest-Elements.py b/658-Find-K-Closest-Elements.py
deleted file mode 100644
index a80f8c5d4..000000000
--- a/658-Find-K-Closest-Elements.py
+++ /dev/null
@@ -1,42 +0,0 @@
-# Log(n) + k
-# More code but also more intuitive
-class Solution:
- def findClosestElements(self, arr: List[int], k: int, x: int) -> List[int]:
- l, r = 0, len(arr) - 1
-
- # Find index of x or the closest val to x
- val, idx = arr[0], 0
- while l <= r:
- m = (l + r) // 2
- curDiff, resDiff = abs(arr[m] - x), abs(val - x)
- if (curDiff < resDiff or
- (curDiff == resDiff and arr[m] < val)):
- val, idx = arr[m], m
-
- if arr[m] < x: l = m + 1
- elif arr[m] > x: r = m - 1
- else: break
-
- l = r = idx
- for i in range(k - 1):
- if l == 0:
- r += 1
- elif r == len(arr) - 1 or x - arr[l-1] <= arr[r+1] - x:
- l -= 1
- else:
- r += 1
- return arr[l:r+1]
-
-# Log(n-k) + k
-# Elegant but very difficult to understand
-class Solution:
- def findClosestElements(self, arr: List[int], k: int, x: int) -> List[int]:
- l, r = 0, len(arr) - k
-
- while l < r:
- m = (l + r) // 2
- if x - arr[m] > arr[m + k] - x:
- l = m + 1
- else:
- r = m
- return arr[l:l+k]
diff --git a/66-Plus-One.py b/66-Plus-One.py
deleted file mode 100644
index a13ba3d6a..000000000
--- a/66-Plus-One.py
+++ /dev/null
@@ -1,18 +0,0 @@
-class Solution:
- def plusOne(self, digits: List[int]) -> List[int]:
- one = 1
- i = 0
- digits = digits[::-1]
-
- while one:
- if i < len(digits):
- if digits[i] == 9:
- digits[i] = 0
- else:
- digits[i] += 1
- one = 0
- else:
- digits.append(one)
- one = 0
- i += 1
- return digits[::-1]
diff --git a/673-Number-of-Longest-Increasing-Subsequence.py b/673-Number-of-Longest-Increasing-Subsequence.py
deleted file mode 100644
index 7e84ab9d4..000000000
--- a/673-Number-of-Longest-Increasing-Subsequence.py
+++ /dev/null
@@ -1,52 +0,0 @@
-class Solution:
- def findNumberOfLIS(self, nums: List[int]) -> int:
- # 1. O(n^2) Recursive solution with Caching
-
- dp = {} # key = index, value = [length of LIS, count]
- lenLIS, res = 0, 0 # length of LIS, count of LIS
-
- def dfs(i):
- if i in dp: return dp[i]
-
- maxLen, maxCnt = 1, 1 # length and count of LIS
- for j in range(i + 1, len(nums)):
- if nums[j] > nums[i]: # make sure increasing order
- length, count = dfs(j)
- if length + 1 > maxLen:
- maxLen, maxCnt = length + 1, count
- elif length + 1 == maxLen:
- maxCnt += count
- nonlocal lenLIS, res
- if maxLen > lenLIS:
- lenLIS, res = maxLen, maxCnt
- elif maxLen == lenLIS:
- res += maxCnt
- dp[i] = [maxLen, maxCnt]
- return dp[i]
-
- for i in range(len(nums)): dfs(i)
- return res
-
- # 2. O(n^2) Dynamic Programming
-
- dp = {} # key = index, value = [length of LIS, count]
- lenLIS, res = 0, 0 # length of LIS, count of LIS
-
- # i = start of subseq
- for i in range(len(nums) - 1, -1, -1):
- maxLen, maxCnt = 1, 1 # len, cnt of LIS start from i
-
- for j in range(i + 1, len(nums)):
- if nums[j] > nums[i]:
- length, count = dp[j] # len, cnt of LIS start from j
- if length + 1 > maxLen:
- maxLen, maxCnt = length + 1, count
- elif length + 1 == maxLen:
- maxCnt += count
- if maxLen > lenLIS:
- lenLIS, res = maxLen, maxCnt
- elif maxLen == lenLIS:
- res += maxCnt
- dp[i] = [maxLen, maxCnt]
-
- return res
diff --git a/678-Valid-Parenthesis-String.py b/678-Valid-Parenthesis-String.py
deleted file mode 100644
index 16d154fa5..000000000
--- a/678-Valid-Parenthesis-String.py
+++ /dev/null
@@ -1,39 +0,0 @@
-# Dynamic Programming: O(n^2)
-class Solution:
- def checkValidString(self, s: str) -> bool:
- dp = { (len(s), 0) : True } # key=(i, leftCount) -> isValid
- def dfs(i, left):
- if i == len(s) or left < 0:
- return left == 0
- if (i, left) in dp:
- return dp[(i, left)]
-
- if s[i] == "(":
- dp[(i, left)] = dfs(i + 1, left + 1)
- elif s[i] == ")":
- dp[(i, left)] = dfs(i + 1, left - 1)
- else:
- dp[(i, left)] = (dfs(i + 1, left + 1) or
- dfs(i + 1, left - 1) or
- dfs(i + 1, left))
- return dp[(i, left)]
-
- return dfs(0, 0)
-
-# Greedy: O(n)
-class Solution:
- def checkValidString(self, s: str) -> bool:
- leftMin, leftMax = 0, 0
-
- for c in s:
- if c == "(":
- leftMin, leftMax = leftMin + 1, leftMax + 1
- elif c == ")":
- leftMin, leftMax = leftMin - 1, leftMax - 1
- else:
- leftMin, leftMax = leftMin - 1, leftMax + 1
- if leftMax < 0:
- return False
- if leftMin < 0: # required because -> s = ( * ) (
- leftMin = 0
- return leftMin == 0
diff --git a/684-Redundant-Connection.py b/684-Redundant-Connection.py
deleted file mode 100644
index 0b1c7ed17..000000000
--- a/684-Redundant-Connection.py
+++ /dev/null
@@ -1,28 +0,0 @@
-class Solution:
- def findRedundantConnection(self, edges: List[List[int]]) -> List[int]:
- par = [i for i in range(len(edges) + 1)]
- rank = [1] * (len(edges) + 1)
-
- def find(n):
- p = par[n]
- while p != par[p]:
- par[p] = par[par[p]]
- p = par[p]
- return p
-
- # return False if already unioned
- def union(n1, n2):
- p1, p2 = find(n1), find(n2)
-
- if p1 == p2: return False
- if rank[p1] > rank[p2]:
- par[p2] = p1
- rank[p1] += rank[p2]
- else:
- par[p1] = p2
- rank[p2] += rank[p1]
- return True
-
- for n1, n2 in edges:
- if not union(n1, n2):
- return [n1, n2]
diff --git a/695-Max-Area-of-Island.py b/695-Max-Area-of-Island.py
deleted file mode 100644
index 8ca570a6a..000000000
--- a/695-Max-Area-of-Island.py
+++ /dev/null
@@ -1,19 +0,0 @@
-class Solution:
- def maxAreaOfIsland(self, grid: List[List[int]]) -> int:
- ROWS, COLS = len(grid), len(grid[0])
- visit = set()
-
- def dfs(r, c):
- if (r < 0 or r == ROWS or c < 0 or c == COLS or
- grid[r][c] == 0 or (r, c) in visit):
- return 0
- visit.add((r, c))
- return (1 + dfs(r + 1, c) +
- dfs(r - 1, c) +
- dfs(r, c + 1) +
- dfs(r, c - 1))
- area = 0
- for r in range(ROWS):
- for c in range(COLS):
- area = max(area, dfs(r, c))
- return area
diff --git a/7-Reverse-Integer.py b/7-Reverse-Integer.py
deleted file mode 100644
index 9d858a78f..000000000
--- a/7-Reverse-Integer.py
+++ /dev/null
@@ -1,22 +0,0 @@
-class Solution:
- def reverse(self, x: int) -> int:
- # Integer.MAX_VALUE = 2147483647 (end with 7)
- # Integer.MIN_VALUE = -2147483648 (end with -8 )
-
- MIN = -2147483648 # -2^31,
- MAX = 2147483647 # 2^31 - 1
-
- res = 0
- while x:
- digit = int(math.fmod(x, 10)) # (python dumb) -1 % 10 = 9
- x = int(x / 10) # (python dumb) -1 // 10 = -1
-
- if (res > MAX // 10 or
- (res == MAX // 10 and digit >= MAX % 10)):
- return 0
- if (res < MIN // 10 or
- (res == MIN // 10 and digit <= MIN % 10)):
- return 0
- res = (res * 10) + digit
-
- return res
diff --git a/70-Climbing-Stairs.py b/70-Climbing-Stairs.py
deleted file mode 100644
index 2bb252058..000000000
--- a/70-Climbing-Stairs.py
+++ /dev/null
@@ -1,10 +0,0 @@
-class Solution:
- def climbStairs(self, n: int) -> int:
- if n <= 3: return n
- n1, n2 = 2, 3
-
- for i in range(4, n + 1):
- temp = n1 + n2
- n1 = n2
- n2 = temp
- return n2
diff --git a/703-Kth-Largest-Element-in-a-Stream.py b/703-Kth-Largest-Element-in-a-Stream.py
deleted file mode 100644
index fc4ee26b4..000000000
--- a/703-Kth-Largest-Element-in-a-Stream.py
+++ /dev/null
@@ -1,14 +0,0 @@
-class KthLargest:
-
- def __init__(self, k: int, nums: List[int]):
- # minHeap w/ K largest integers
- self.minHeap, self.k = nums, k
- heapq.heapify(self.minHeap)
- while len(self.minHeap) > k:
- heapq.heappop(self.minHeap)
-
- def add(self, val: int) -> int:
- heapq.heappush(self.minHeap, val)
- if len(self.minHeap) > self.k:
- heapq.heappop(self.minHeap)
- return self.minHeap[0]
diff --git a/704-Binary-Search.py b/704-Binary-Search.py
deleted file mode 100644
index 88eb0325c..000000000
--- a/704-Binary-Search.py
+++ /dev/null
@@ -1,13 +0,0 @@
-class Solution:
- def search(self, nums: List[int], target: int) -> int:
- l, r = 0, len(nums) - 1
-
- while l <= r:
- m = l + ((r - l) // 2) # (l + r) // 2 can lead to overflow
- if nums[m] > target:
- r = m - 1
- elif nums[m] < target:
- l = m + 1
- else:
- return m
- return -1
diff --git a/72-Edit-Distance.py b/72-Edit-Distance.py
deleted file mode 100644
index dc84dc7a9..000000000
--- a/72-Edit-Distance.py
+++ /dev/null
@@ -1,16 +0,0 @@
-class Solution:
- def minDistance(self, word1: str, word2: str) -> int:
- dp = [[float("inf")] * (len(word2) + 1) for i in range(len(word1) + 1)]
-
- for j in range(len(word2) + 1):
- dp[len(word1)][j] = len(word2) - j
- for i in range(len(word1) + 1):
- dp[i][len(word2)] = len(word1) - i
-
- for i in range(len(word1) - 1, -1, -1):
- for j in range(len(word2) - 1, -1, -1):
- if word1[i] == word2[j]:
- dp[i][j] = dp[i + 1][j + 1]
- else:
- dp[i][j] = 1 + min(dp[i + 1][j], dp[i][j + 1], dp[i + 1][j + 1])
- return dp[0][0]
diff --git a/724-Find-Pivot-Index.py b/724-Find-Pivot-Index.py
deleted file mode 100644
index 1a094985f..000000000
--- a/724-Find-Pivot-Index.py
+++ /dev/null
@@ -1,11 +0,0 @@
-class Solution:
- def pivotIndex(self, nums: List[int]) -> int:
- total = sum(nums) # O(n)
-
- leftSum = 0
- for i in range(len(nums)):
- rightSum = total - nums[i] - leftSum
- if leftSum == rightSum:
- return i
- leftSum += nums[i]
- return -1
diff --git a/73-Set-Matrix-Zeroes.py b/73-Set-Matrix-Zeroes.py
deleted file mode 100644
index 4c960ec64..000000000
--- a/73-Set-Matrix-Zeroes.py
+++ /dev/null
@@ -1,28 +0,0 @@
-class Solution:
- def setZeroes(self, matrix: List[List[int]]) -> None:
- # O(1)
- ROWS, COLS = len(matrix), len(matrix[0])
- rowZero = False
-
- # determine which rows/cols need to be zero
- for r in range(ROWS):
- for c in range(COLS):
- if matrix[r][c] == 0:
- matrix[0][c] = 0
- if r > 0:
- matrix[r][0] = 0
- else:
- rowZero = True
-
- for r in range(1, ROWS):
- for c in range(1, COLS):
- if matrix[0][c] == 0 or matrix[r][0] == 0:
- matrix[r][c] = 0
-
- if matrix[0][0] == 0:
- for r in range(ROWS):
- matrix[r][0] = 0
-
- if rowZero:
- for c in range(COLS):
- matrix[0][c] = 0
diff --git a/739-Daily-Temperatures.py b/739-Daily-Temperatures.py
deleted file mode 100644
index 7939d4779..000000000
--- a/739-Daily-Temperatures.py
+++ /dev/null
@@ -1,11 +0,0 @@
-class Solution:
- def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
- res = [0] * len(temperatures)
- stack = [] # pair: [temp, index]
-
- for i, t in enumerate(temperatures):
- while stack and t > stack[-1][0]:
- stackT, stackInd = stack.pop()
- res[stackInd] = (i - stackInd)
- stack.append([t, i])
- return res
diff --git a/74-Search-a-2D-Matrix.py b/74-Search-a-2D-Matrix.py
deleted file mode 100644
index 84c7ff2c3..000000000
--- a/74-Search-a-2D-Matrix.py
+++ /dev/null
@@ -1,27 +0,0 @@
-class Solution:
- def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
- ROWS, COLS = len(matrix), len(matrix[0])
-
- top, bot = 0, ROWS - 1
- while top <= bot:
- row = (top + bot) // 2
- if target > matrix[row][-1]:
- top = row + 1
- elif target < matrix[row][0]:
- bot = row - 1
- else:
- break
-
- if not (top <= bot):
- return False
- row = (top + bot) // 2
- l, r = 0, COLS - 1
- while l <= r:
- m = (l + r) // 2
- if target > matrix[row][m]:
- l = m + 1
- elif target < matrix[row][m]:
- r = m - 1
- else:
- return True
- return False
diff --git a/743-Network-Delay-Time.py b/743-Network-Delay-Time.py
deleted file mode 100644
index beb6613ec..000000000
--- a/743-Network-Delay-Time.py
+++ /dev/null
@@ -1,22 +0,0 @@
-class Solution:
- def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int:
- edges = collections.defaultdict(list)
- for u, v, w in times:
- edges[u].append((v, w))
-
- minHeap = [(0, k)]
- visit = set()
- t = 0
- while minHeap:
- w1, n1 = heapq.heappop(minHeap)
- if n1 in visit:
- continue
- visit.add(n1)
- t = max(t, w1)
-
- for n2, w2 in edges[n1]:
- if n2 not in visit:
- heapq.heappush(minHeap, (w1 + w2, n2))
- return t if len(visit) == n else -1
-
- # O(E * logV)
diff --git a/746-Min-Cost-Climbing-Stairs.py b/746-Min-Cost-Climbing-Stairs.py
deleted file mode 100644
index e7ceadc8e..000000000
--- a/746-Min-Cost-Climbing-Stairs.py
+++ /dev/null
@@ -1,8 +0,0 @@
-class Solution:
- def minCostClimbingStairs(self, cost: List[int]) -> int:
- cost.append(0)
-
- for i in range(len(cost) - 3, -1, -1):
- cost[i] += min(cost[i + 1], cost[i + 2])
-
- return min(cost[0], cost[1])
diff --git a/752-Open-the-Lock.py b/752-Open-the-Lock.py
deleted file mode 100644
index 179ea8504..000000000
--- a/752-Open-the-Lock.py
+++ /dev/null
@@ -1,26 +0,0 @@
-class Solution:
- def openLock(self, deadends: List[str], target: str) -> int:
- if "0000" in deadends:
- return -1
-
- def children(wheel):
- res = []
- for i in range(4):
- digit = str((int(wheel[i]) + 1) % 10)
- res.append(wheel[:i] + digit + wheel[i+1:])
- digit = str((int(wheel[i]) + 10 - 1) % 10)
- res.append(wheel[:i] + digit + wheel[i+1:])
- return res
-
- q = deque()
- visit = set(deadends)
- q.append(["0000", 0]) # [wheel, turns]
- while q:
- wheel, turns = q.popleft()
- if wheel == target:
- return turns
- for child in children(wheel):
- if child not in visit:
- visit.add(child)
- q.append([child, turns + 1])
- return -1
diff --git a/76-Minimum-Window-Substring.py b/76-Minimum-Window-Substring.py
deleted file mode 100644
index 9f601bb57..000000000
--- a/76-Minimum-Window-Substring.py
+++ /dev/null
@@ -1,30 +0,0 @@
-class Solution:
- def minWindow(self, s: str, t: str) -> str:
- if t == "": return ""
-
- countT, window = {}, {}
- for c in t:
- countT[c] = 1 + countT.get(c, 0)
-
- have, need = 0, len(countT)
- res, resLen = [-1, -1], float("infinity")
- l = 0
- for r in range(len(s)):
- c = s[r]
- window[c] = 1 + window.get(c, 0)
-
- if c in countT and window[c] == countT[c]:
- have += 1
-
- while have == need:
- # update our result
- if (r - l + 1) < resLen:
- res = [l, r]
- resLen = (r - l + 1)
- # pop from the left of our window
- window[s[l]] -= 1
- if s[l] in countT and window[s[l]] < countT[s[l]]:
- have -= 1
- l += 1
- l, r = res
- return s[l:r+1] if resLen != float("infinity") else ""
diff --git a/763-Partition-Labels.py b/763-Partition-Labels.py
deleted file mode 100644
index 0594c1d39..000000000
--- a/763-Partition-Labels.py
+++ /dev/null
@@ -1,21 +0,0 @@
-class Solution:
- def partitionLabels(self, S: str) -> List[int]:
- count = {}
- res = []
- i, length = 0, len(S)
- for j in range(length):
- c = S[j]
- count[c] = j
-
- curLen = 0
- goal = 0
- while i < length:
- c = S[i]
- goal = max(goal, count[c])
- curLen += 1
-
- if goal == i:
- res.append(curLen)
- curLen = 0
- i += 1
- return res
diff --git a/767-Reorganize-String.py b/767-Reorganize-String.py
deleted file mode 100644
index 85cd89593..000000000
--- a/767-Reorganize-String.py
+++ /dev/null
@@ -1,22 +0,0 @@
-class Solution:
- def reorganizeString(self, s: str) -> str:
- count = Counter(s) # Hashmap, count each char
- maxHeap = [[-cnt, char] for char, cnt in count.items()]
- heapq.heapify(maxHeap) # O(n)
-
- prev = None
- res = ""
- while maxHeap or prev:
- if prev and not maxHeap:
- return ""
- # most frequent, except prev
- cnt, char = heapq.heappop(maxHeap)
- res += char
- cnt += 1
-
- if prev:
- heapq.heappush(maxHeap, prev)
- prev = None
- if cnt != 0:
- prev = [cnt, char]
- return res
diff --git a/778-Swim-in-Rising-Water.py b/778-Swim-in-Rising-Water.py
deleted file mode 100644
index d00030567..000000000
--- a/778-Swim-in-Rising-Water.py
+++ /dev/null
@@ -1,20 +0,0 @@
-class Solution:
- def swimInWater(self, grid: List[List[int]]) -> int:
- N = len(grid)
- visit = set()
- minH = [[grid[0][0], 0, 0]] # (time/max-height, r, c)
- directions = [[0, 1], [0, -1], [1, 0], [-1 ,0]]
-
- visit.add((0, 0))
- while minH:
- t, r, c = heapq.heappop(minH)
- if r == N - 1 and c == N - 1:
- return t
- for dr, dc in directions:
- neiR, neiC = r + dr, c + dc
- if (neiR < 0 or neiC < 0 or
- neiR == N or neiC == N or
- (neiR, neiC) in visit):
- continue
- visit.add((neiR, neiC))
- heapq.heappush(minH, [max(t, grid[neiR][neiC]), neiR, neiC])
diff --git a/78-Subsets.py b/78-Subsets.py
deleted file mode 100644
index 206dc54b2..000000000
--- a/78-Subsets.py
+++ /dev/null
@@ -1,18 +0,0 @@
-class Solution:
- def subsets(self, nums: List[int]) -> List[List[int]]:
- res = []
-
- subset = []
- def dfs(i):
- if i >= len(nums):
- res.append(subset.copy())
- return
- # decision to include nums[i]
- subset.append(nums[i])
- dfs(i + 1)
- # decision NOT to include nums[i]
- subset.pop()
- dfs(i + 1)
-
- dfs(0)
- return res
diff --git a/787-Cheapest-Flights-within-K-stops.py b/787-Cheapest-Flights-within-K-stops.py
deleted file mode 100644
index 767e1b98e..000000000
--- a/787-Cheapest-Flights-within-K-stops.py
+++ /dev/null
@@ -1,15 +0,0 @@
-class Solution:
- def findCheapestPrice(self, n: int, flights: List[List[int]], src: int, dst: int, k: int) -> int:
- prices = [float("inf")] * n
- prices[src] = 0
-
- for i in range(k + 1):
- tmpPrices = prices.copy()
-
- for s, d, p in flights: # s=source, d=dest, p=price
- if prices[s] == float("inf"):
- continue
- if prices[s] + p < tmpPrices[d]:
- tmpPrices[d] = prices[s] + p
- prices = tmpPrices
- return -1 if prices[dst] == float("inf") else prices[dst]
diff --git a/79-Word-Search.py b/79-Word-Search.py
deleted file mode 100644
index 5c6b99a42..000000000
--- a/79-Word-Search.py
+++ /dev/null
@@ -1,25 +0,0 @@
-class Solution:
- def exist(self, board: List[List[str]], word: str) -> bool:
- ROWS, COLS = len(board), len(board[0])
- path = set()
-
- def dfs(r, c, i):
- if i == len(word):
- return True
- if (min(r, c) < 0 or r >= ROWS or c >= COLS or
- word[i] != board[r][c] or (r, c) in path):
- return False
- path.add((r, c))
- res = (dfs(r + 1, c, i + 1) or
- dfs(r - 1, c, i + 1) or
- dfs(r, c + 1, i + 1) or
- dfs(r, c - 1, i + 1))
- path.remove((r, c))
- return res
-
- for r in range(ROWS):
- for c in range(COLS):
- if dfs(r, c, 0): return True
- return False
-
- # O(n * m * 4^n)
diff --git a/84-Largest-Rectangle-in-Histogram.py b/84-Largest-Rectangle-in-Histogram.py
deleted file mode 100644
index 8f84af583..000000000
--- a/84-Largest-Rectangle-in-Histogram.py
+++ /dev/null
@@ -1,16 +0,0 @@
-class Solution:
- def largestRectangleArea(self, heights: List[int]) -> int:
- maxArea = 0
- stack = [] # pair: (index, height)
-
- for i, h in enumerate(heights):
- start = i
- while stack and stack[-1][1] > h:
- index, height = stack.pop()
- maxArea = max(maxArea, height * (i - index))
- start = index
- stack.append((start, h))
-
- for i, h in stack:
- maxArea = max(maxArea, h * (len(heights) - i))
- return maxArea
diff --git a/846-Hand-of-Straights.py b/846-Hand-of-Straights.py
deleted file mode 100644
index 9f31c956b..000000000
--- a/846-Hand-of-Straights.py
+++ /dev/null
@@ -1,22 +0,0 @@
-class Solution:
- def isNStraightHand(self, hand: List[int], groupSize: int) -> bool:
- if len(hand) % groupSize:
- return False
-
- count = {}
- for n in hand:
- count[n] = 1 + count.get(n, 0)
-
- minH = list(count.keys())
- heapq.heapify(minH)
- while minH:
- first = minH[0]
- for i in range(first, first + groupSize):
- if i not in count:
- return False
- count[i] -= 1
- if count[i] == 0:
- if i != minH[0]:
- return False
- heapq.heappop(minH)
- return True
diff --git a/853-Car-Fleet.py b/853-Car-Fleet.py
deleted file mode 100644
index 6290852fa..000000000
--- a/853-Car-Fleet.py
+++ /dev/null
@@ -1,10 +0,0 @@
-class Solution:
- def carFleet(self, target: int, position: List[int], speed: List[int]) -> int:
- pair = [[p, s] for p, s in zip(position, speed)]
-
- stack = []
- for p, s in sorted(pair)[::-1]: # Reverse Sorted Order
- stack.append((target - p) / s)
- if len(stack) >= 2 and stack[-1] <= stack[-2]:
- stack.pop()
- return len(stack)
diff --git a/875-Koko-Eating-Bananas.py b/875-Koko-Eating-Bananas.py
deleted file mode 100644
index cfb701141..000000000
--- a/875-Koko-Eating-Bananas.py
+++ /dev/null
@@ -1,17 +0,0 @@
-class Solution:
- def minEatingSpeed(self, piles: List[int], H: int) -> int:
- l, r = 1, max(piles)
- k = 0
-
- while l <= r:
- m = (l + r) // 2
-
- totalTime = 0
- for p in piles:
- totalTime += ((p-1)//m) + 1
- if totalTime <= H:
- k = m
- r = m - 1
- else:
- l = m + 1
- return k
diff --git a/90-Subsets-II.py b/90-Subsets-II.py
deleted file mode 100644
index b951812fb..000000000
--- a/90-Subsets-II.py
+++ /dev/null
@@ -1,20 +0,0 @@
-class Solution:
- def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
- res = []
- nums.sort()
-
- def backtrack(i, subset):
- if i == len(nums):
- res.append(subset[::])
- return
-
- # All subsets that include nums[i]
- subset.append(nums[i])
- backtrack(i + 1, subset)
- subset.pop()
- # All subsets that don't include nums[i]
- while i + 1 < len(nums) and nums[i] == nums[i+1]:
- i += 1
- backtrack(i + 1, subset)
- backtrack(0, [])
- return res
diff --git a/909-Snakes-and-Ladders.py b/909-Snakes-and-Ladders.py
deleted file mode 100644
index b2338d7f0..000000000
--- a/909-Snakes-and-Ladders.py
+++ /dev/null
@@ -1,27 +0,0 @@
-class Solution:
- def snakesAndLadders(self, board: List[List[int]]) -> int:
- length = len(board)
- board.reverse()
- def intToPos(square):
- r = (square - 1) // length
- c = (square - 1) % length
- if r % 2:
- c = length - 1 - c
- return [r, c]
-
- q = deque()
- q.append([1, 0]) # [square, moves]
- visit = set()
- while q:
- square, moves = q.popleft()
- for i in range(1, 7):
- nextSquare = square + i
- r, c = intToPos(nextSquare)
- if board[r][c] != -1:
- nextSquare = board[r][c]
- if nextSquare == length * length:
- return moves + 1
- if nextSquare not in visit:
- visit.add(nextSquare)
- q.append([nextSquare, moves + 1])
- return -1
diff --git a/91-Decode-ways.py b/91-Decode-ways.py
deleted file mode 100644
index 9b7fbd28e..000000000
--- a/91-Decode-ways.py
+++ /dev/null
@@ -1,30 +0,0 @@
-class Solution:
- def numDecodings(self, s: str) -> int:
- # Memoization
- dp = { len(s) : 1 }
- def dfs(i):
- if i in dp:
- return dp[i]
- if s[i] == "0":
- return 0
-
- res = dfs(i + 1)
- if (i + 1 < len(s) and (s[i] == "1" or
- s[i] == "2" and s[i + 1] in "0123456")):
- res += dfs(i + 2)
- dp[i] = res
- return res
- return dfs(0)
-
- # Dynamic Programming
- dp = { len(s) : 1 }
- for i in range(len(s) - 1, -1, -1):
- if s[i] == "0":
- dp[i] = 0
- else:
- dp[i] = dp[i + 1]
-
- if (i + 1 < len(s) and (s[i] == "1" or
- s[i] == "2" and s[i + 1] in "0123456")):
- dp[i] += dp[i + 2]
- return dp[0]
diff --git a/92-Reverse-Linked-List-II.py b/92-Reverse-Linked-List-II.py
deleted file mode 100644
index 6a9676fb1..000000000
--- a/92-Reverse-Linked-List-II.py
+++ /dev/null
@@ -1,21 +0,0 @@
-class Solution:
- def reverseBetween(self, head: Optional[ListNode], left: int, right: int) -> Optional[ListNode]:
- dummy = ListNode(0, head)
-
- # 1) reach node at position "left"
- leftPrev, cur = dummy, head
- for i in range(left - 1):
- leftPrev, cur = cur, cur.next
-
- # Now cur="left", leftPrev="node before left"
- # 2) reverse from left to right
- prev = None
- for i in range(right - left + 1):
- tmpNext = cur.next
- cur.next = prev
- prev, cur = cur, tmpNext
-
- # 3) Update pointers
- leftPrev.next.next = cur # cur is node after "right"
- leftPrev.next = prev # prev is "right"
- return dummy.next
diff --git a/94-Binary-Tree-Inorder-Traversal.py b/94-Binary-Tree-Inorder-Traversal.py
deleted file mode 100644
index 85ab49cc6..000000000
--- a/94-Binary-Tree-Inorder-Traversal.py
+++ /dev/null
@@ -1,26 +0,0 @@
-class Solution:
- def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
- # Iterative
- res, stack = [], []
- cur = root
-
- while cur or stack:
- while cur:
- stack.append(cur)
- cur = cur.left
- cur = stack.pop()
- res.append(cur.val)
- cur = cur.right
- return res
-
- # Recursive
- res = []
-
- def helper(root):
- if not root:
- return
- helper(root.left)
- res.append(root.val)
- helper(root.right)
- helper(root)
- return res
diff --git a/97-Interleaving-Strings.py b/97-Interleaving-Strings.py
deleted file mode 100644
index 3a0a149d3..000000000
--- a/97-Interleaving-Strings.py
+++ /dev/null
@@ -1,15 +0,0 @@
-class Solution:
- def isInterleave(self, s1: str, s2: str, s3: str) -> bool:
- if len(s1) + len(s2) != len(s3):
- return False
-
- dp = [ [False] * (len(s2) + 1) for i in range(len(s1) + 1)]
- dp[len(s1)][len(s2)] = True
-
- for i in range(len(s1), -1, -1):
- for j in range(len(s2), -1, -1):
- if i < len(s1) and s1[i] == s3[i + j] and dp[i + 1][j]:
- dp[i][j] = True
- if j < len(s2) and s2[j] == s3[i + j] and dp[i][j + 1]:
- dp[i][j] = True
- return dp[0][0]
diff --git a/973-K-Closest-Points-to-Origin.py b/973-K-Closest-Points-to-Origin.py
deleted file mode 100644
index 1318017cf..000000000
--- a/973-K-Closest-Points-to-Origin.py
+++ /dev/null
@@ -1,13 +0,0 @@
-class Solution:
- def kClosest(self, points: List[List[int]], k: int) -> List[List[int]]:
- pts = []
- for x, y in points:
- dist = (abs(x - 0) ** 2) + (abs(y - 0) ** 2)
- pts.append([dist, x, y])
-
- res = []
- heapq.heapify(pts)
- for i in range(k):
- dist, x, y = heapq.heappop(pts)
- res.append([x, y])
- return res
diff --git a/98-Validate-Binary-Search-Tree.py b/98-Validate-Binary-Search-Tree.py
deleted file mode 100644
index bdf5228be..000000000
--- a/98-Validate-Binary-Search-Tree.py
+++ /dev/null
@@ -1,19 +0,0 @@
-# Definition for a binary tree node.
-# class TreeNode:
-# def __init__(self, val=0, left=None, right=None):
-# self.val = val
-# self.left = left
-# self.right = right
-class Solution:
- def isValidBST(self, root: TreeNode) -> bool:
-
- def valid(node, left, right):
- if not node:
- return True
- if not (node.val < right and node.val > left):
- return False
-
- return (valid(node.left, left, node.val) and
- valid(node.right, node.val, right))
-
- return valid(root, float("-inf"), float("inf"))
diff --git a/981-Time-Based-Key-Value-Store.py b/981-Time-Based-Key-Value-Store.py
deleted file mode 100644
index d762fd774..000000000
--- a/981-Time-Based-Key-Value-Store.py
+++ /dev/null
@@ -1,24 +0,0 @@
-class TimeMap:
-
- def __init__(self):
- """
- Initialize your data structure here.
- """
- self.keyStore = {} # key : list of [val, timestamp]
-
- def set(self, key: str, value: str, timestamp: int) -> None:
- if key not in self.keyStore:
- self.keyStore[key] = []
- self.keyStore[key].append([value, timestamp])
-
- def get(self, key: str, timestamp: int) -> str:
- res, values = "", self.keyStore.get(key, [])
- l, r = 0, len(values) - 1
- while l <= r:
- m = (l + r) // 2
- if values[m][1] <= timestamp:
- res = values[m][0]
- l = m + 1
- else:
- r = m - 1
- return res
diff --git a/994-Rotting-Oranges.py b/994-Rotting-Oranges.py
deleted file mode 100644
index 0f9afce04..000000000
--- a/994-Rotting-Oranges.py
+++ /dev/null
@@ -1,31 +0,0 @@
-class Solution:
- def orangesRotting(self, grid: List[List[int]]) -> int:
- q = collections.deque()
- fresh = 0
- time = 0
-
- for r in range(len(grid)):
- for c in range(len(grid[0])):
- if grid[r][c] == 1:
- fresh += 1
- if grid[r][c] == 2:
- q.append((r, c))
-
- directions = [[0, 1], [0, -1], [1, 0], [-1, 0]]
- while fresh > 0 and q:
- length = len(q)
- for i in range(length):
- r, c = q.popleft()
-
- for dr, dc in directions:
- row, col = r + dr, c + dc
- # if in bounds and nonrotten, make rotten
- # and add to q
- if row in range(len(grid)) and \
- col in range(len(grid[0])) and \
- grid[row][col] == 1:
- grid[row][col] = 2
- q.append((row, col))
- fresh -= 1
- time += 1
- return time if fresh == 0 else -1
diff --git a/README.md b/README.md
index 82c045bf8..2ed6e260d 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,19 @@
-# Leetcode solutions for [NeetCode](https://www.youtube.com/c/neetcode)
+# Leetcode solutions for [NeetCode](https://www.youtube.com/c/neetcode) in C#
-### Contributing
+This is my personal fork of https://github.com/neetcode-gh/leetcode.
+I am adding C# solutions to the [blind 75](https://neetcode.io/practice?tab=blind75) collection of problems.
-I mostly do solutions in Python, but if you would like to contribute solutions for other common languages like Java, C++ and JavaScript, please feel free to make a pull request! :)
+## Update
+
+In the meantime, C# solutions were added to the main repo, but I prefer working with my sln/proj setup as it allows for quick testing in the IDE.
+
+### Naming convention
+
+For each exercise in we add :
+- a folder in `csharp//main`
+- a .cs file in `csharp//testCases`
+
+The name of the folder/files is `N-L-`, where :
+- `` is the position of the exercise in https://neetcode.io/
+- `` is the number of the same exercise in LeetCode
+- `` is the name of the problem on neetCode within its group
diff --git a/cpp/1-Two-Sum.cpp b/cpp/1-Two-Sum.cpp
deleted file mode 100644
index 17024747a..000000000
--- a/cpp/1-Two-Sum.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-class Solution {
-public:
- vector twoSum(vector& nums, int target) {
- unordered_map umap;
- for(int i=0; ival != q->val) return false;
-
- return isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
- }
-};
\ No newline at end of file
diff --git a/cpp/102-Binary-Tree-Level-Order-Traversal.cpp b/cpp/102-Binary-Tree-Level-Order-Traversal.cpp
deleted file mode 100644
index 1f06b64d8..000000000
--- a/cpp/102-Binary-Tree-Level-Order-Traversal.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * Definition for a binary tree node.
- * struct TreeNode {
- * int val;
- * TreeNode *left;
- * TreeNode *right;
- * TreeNode() : val(0), left(nullptr), right(nullptr) {}
- * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
- * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
- * };
- */
-
-class Solution {
-public:
- vector> levelOrder(TreeNode* root) {
- queue< TreeNode* > q;
- q.push(root);
- vector> v;
- vector k;
- TreeNode* c;
- int j;
- while(!q.empty() )
- {
- k.clear();
- j=q.size();
- for(int i=0;ival);
- q.push(c->left);
- q.push(c->right);
- }
- }
- if(!k.empty())
- v.push_back(k);
-
- }
- return v;
-
- }
-};
diff --git a/cpp/104-Maximum-Depth-of-Binary-Tree.cpp b/cpp/104-Maximum-Depth-of-Binary-Tree.cpp
deleted file mode 100644
index bae6eb041..000000000
--- a/cpp/104-Maximum-Depth-of-Binary-Tree.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * Definition for a binary tree node.
- * struct TreeNode {
- * int val;
- * TreeNode *left;
- * TreeNode *right;
- * TreeNode() : val(0), left(nullptr), right(nullptr) {}
- * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
- * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
- * };
- */
-
-// Using Stack
-// class Solution {
-// public:
-// int maxDepth(TreeNode* root) {
-// if (root == NULL) return 0;
-// stack> stk;
-// int res = 0;
-// stk.push({root, 1});
-
-// while (!stk.empty()) {
-// auto t = stk.top();
-// res = max(res, t.second);
-// stk.pop();
-// if (t.first->left) stk.push({t.first->left, t.second+1});
-// if (t.first->right) stk.push({t.first->right, t.second+1});
-// }
-// return res;
-// }
-// };
-
-// Using Recursion
-class Solution {
-public:
- int maxDepth(TreeNode* root) {
- if (root == NULL) return 0;
- return max(maxDepth(root->left)+1, maxDepth(root->right)+1);
- }
-};
\ No newline at end of file
diff --git a/cpp/1046-Last-Stone-Weight.cpp b/cpp/1046-Last-Stone-Weight.cpp
deleted file mode 100644
index 572117da0..000000000
--- a/cpp/1046-Last-Stone-Weight.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-class Solution {
-public:
- int lastStoneWeight(vector& stones) {
- priority_queue> pq(stones.begin(), stones.end());
- pq.push(0);
-
- while (pq.size()>=1) {
- int t1 = pq.top();
- pq.pop();
- if(pq.empty()) break;
- int t2 = pq.top();
- pq.pop();
- pq.push(abs(t1-t2));
- }
-
- return pq.top();
- }
-};
\ No newline at end of file
diff --git a/cpp/11-Container-with-most-water.cpp b/cpp/11-Container-with-most-water.cpp
deleted file mode 100644
index dd0e58353..000000000
--- a/cpp/11-Container-with-most-water.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-class Solution {
-public:
- int maxArea(vector& height) {
- int i=0,j=height.size()-1;
- int maxA=0,minh;
- while(imaxA)
- maxA=minh*(j-i);
- if(minh==height[i])
- i++;
- else
- j--;
- }
- return maxA;
- }
-};
diff --git a/cpp/110-Balanced-Binary-Tree.cpp b/cpp/110-Balanced-Binary-Tree.cpp
deleted file mode 100644
index 2804213ee..000000000
--- a/cpp/110-Balanced-Binary-Tree.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * Definition for a binary tree node.
- * struct TreeNode {
- * int val;
- * TreeNode *left;
- * TreeNode *right;
- * TreeNode() : val(0), left(nullptr), right(nullptr) {}
- * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
- * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
- * };
- */
-class Solution {
-public:
-
- int getHeight(TreeNode* root, unordered_map& umap) {
- if (root==NULL) return 0;
- if (umap.find(root) != umap.end()) return umap[root];
- int res = max(getHeight(root->left, umap), getHeight(root->right, umap))+1;
- umap[root] = res;
- return res;
- }
- bool isBalanced(TreeNode* root) {
- unordered_map umap;
- if (root == NULL) return true;
- if (abs(getHeight(root->left, umap) - getHeight(root->right, umap)) > 1) return false;
- return isBalanced(root->left) && isBalanced(root->right);
- }
-};
\ No newline at end of file
diff --git a/cpp/121-Best-Time-to-Buy-and-Sell-Stock.cpp b/cpp/121-Best-Time-to-Buy-and-Sell-Stock.cpp
deleted file mode 100644
index 68b1b3fa2..000000000
--- a/cpp/121-Best-Time-to-Buy-and-Sell-Stock.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-class Solution {
-public:
- int maxProfit(vector& prices) {
- int n = prices.size();
- // Preprocessing
- // Polulate a smallest from beginning array
- // Polulate a largest from the end array
- vector smallest(n, -1), largest(n, -1);
-
- smallest[0] = prices[0];
- largest[n-1] = prices[n-1];
-
- for (int i = 1; i < n; i++) {
- smallest[i] = min(smallest[i-1], prices[i]);
- }
-
- for (int i = n-2; i>=0; i--) {
- largest[i] = max(largest[i+1], prices[i]);
- }
-
- // Logic
- // Max difference b/w the smallest and largest element
- int res = 0;
- for(int i=0; i= 'a' && a <= 'z') a = a-'a'+'A';
- if (b >= 'a' && b <= 'z') b = b - 'a' + 'A';
-
- // Logic
- if ( (a < 'A' || a > 'Z') && (a < '0' || a > '9') ) {
- start ++;
- continue;
- }
- if ( (b < 'A' || b > 'Z') && (b < '0' || b > '9') ) {
- end --;
- continue;
- }
- if(a != b) return false;
- start ++;
- end --;
- }
-
- return true;
- }
-};
\ No newline at end of file
diff --git a/cpp/128-Longest-Consecutive-Sequence.cpp b/cpp/128-Longest-Consecutive-Sequence.cpp
deleted file mode 100644
index 027884c99..000000000
--- a/cpp/128-Longest-Consecutive-Sequence.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-class Solution {
-public:
- int longestConsecutive(vector& nums) {
- unordered_set hs;
- for (int n : nums) {
- hs.insert(n);
- }
-
- int longest = 0;
- for (int n : nums) {
- // if n-1 is not in the set, the element can be the start of a sequence
- if (hs.find(n - 1) == hs.end()) {
- int length = 1;
- while (hs.find(n + length) != hs.end())
- ++length;
- longest = max(longest, length);
- }
- }
- return longest;
- }
-};
diff --git a/cpp/136-Single-Number.cpp b/cpp/136-Single-Number.cpp
deleted file mode 100644
index 5dcfa3909..000000000
--- a/cpp/136-Single-Number.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-// Time complexity : O(n)
-// Space complexity : O(1)
-
-class Solution {
-public:
- int singleNumber(vector& nums) {
- int res = 0;
- for(int num : nums){
- res^=num;
- }
- return res;
- }
-};
diff --git a/cpp/141-Linked-List-Cycle.cpp b/cpp/141-Linked-List-Cycle.cpp
deleted file mode 100644
index c4cfdcceb..000000000
--- a/cpp/141-Linked-List-Cycle.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * Definition for singly-linked list.
- * struct ListNode {
- * int val;
- * ListNode *next;
- * ListNode(int x) : val(x), next(NULL) {}
- * };
- */
-class Solution {
-public:
- bool hasCycle(ListNode *head) {
- if(!head) return 0;
- unordered_set s;
- s.insert(head);
- ListNode * ptr=head->next;
- while(ptr)
- {
- if(s.find(ptr)==s.end())
- {
- s.insert(ptr);
- ptr=ptr->next;
- }
- else
- return 1;
- }
- return 0;
-
- }
-};
diff --git a/cpp/143-Reorder-List.cpp b/cpp/143-Reorder-List.cpp
deleted file mode 100644
index ea6713f15..000000000
--- a/cpp/143-Reorder-List.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * Definition for singly-linked list.
- * struct ListNode {
- * int val;
- * ListNode *next;
- * ListNode() : val(0), next(nullptr) {}
- * ListNode(int x) : val(x), next(nullptr) {}
- * ListNode(int x, ListNode *next) : val(x), next(next) {}
- * };
- */
-class Solution {
- public:
- void reorderList(ListNode* head) {
- ListNode* prev = nullptr;
- ListNode* slow = head;
- ListNode* fast = head;
-
- // set slow to middle node
- while (fast != nullptr && fast->next != nullptr) {
- prev = slow;
- slow = slow->next;
- fast = fast->next->next;
- }
-
- if (prev != nullptr) {
- prev->next = reverseList(slow);
- mergeTwoLists(head, prev->next);
- }
- }
-
- private:
- ListNode* reverseList(ListNode* head) {
- ListNode* prev = nullptr;
- ListNode* curr = head;
-
- while (curr != nullptr) {
- ListNode* next = curr->next;
- curr->next = prev;
- prev = curr;
- curr = next;
- }
-
- return prev;
- }
-
- // invariant: list2 length = [list1 length, list1 length + 1]
- ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) {
- ListNode dummy;
- ListNode* prev = &dummy;
-
- ListNode* l1 = list1;
- ListNode* l2 = list2;
-
- while (l1 != list2) {
- takeNode(prev, l1);
- takeNode(prev, l2);
- }
-
- // handle odd number of nodes
- if (l2 != nullptr) {
- takeNode(prev, l2);
- }
-
- return dummy.next;
- }
-
- void takeNode(ListNode*& prev, ListNode*& curr) {
- prev->next = curr;
- prev = prev->next;
- curr = curr->next;
- }
-};
diff --git a/cpp/15-3Sum.cpp b/cpp/15-3Sum.cpp
deleted file mode 100644
index 3e73121d4..000000000
--- a/cpp/15-3Sum.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-class Solution {
-public:
- vector> threeSum(vector& nums) {
- sort(nums.begin(), nums.end());
- vector> res;
- for (int i = 0; i < nums.size(); ++i) {
- int a = nums[i];
- // triplet should not contain duplicate elements
- if (i > 0 && a == nums[i - 1])
- continue;
- // 2 ptr approach
- int l = i + 1, r = nums.size() - 1;
- while (l < r) {
- int threeSum = a + nums[l] + nums[r];
- if (threeSum > 0)
- r -= 1;
- else if (threeSum < 0)
- l += 1;
- else {
- // found triplet
- res.push_back({ a, nums[l], nums[r] });
- l += 1;
- // skip duplicates
- while (nums[l] == nums[l - 1] && l < r)
- l += 1;
- }
- }
- }
- return res;
- }
-};
diff --git a/cpp/155-Min-Stack.cpp b/cpp/155-Min-Stack.cpp
deleted file mode 100644
index 9b6147762..000000000
--- a/cpp/155-Min-Stack.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-using namespace std;
-class MinStack {
-public:
- stack> stk;
- int m;
-
- MinStack() {
- m = INT_MAX;
- }
-
- void push(int val) {
- stk.push({val, min(val, stk.empty()?INT_MAX:stk.top().second)});
- }
-
- void pop() {
- if(!stk.empty()) stk.pop();
- }
-
- int top() {
- return stk.top().first;
- }
-
- int getMin() {
- return stk.top().second;
- }
-};
-
-/**
- * Your MinStack object will be instantiated and called as such:
- * MinStack* obj = new MinStack();
- * obj->push(val);
- * obj->pop();
- * int param_3 = obj->top();
- * int param_4 = obj->getMin();
- */
\ No newline at end of file
diff --git a/cpp/167-Two-Sum-II.cpp b/cpp/167-Two-Sum-II.cpp
deleted file mode 100644
index 9e9097eae..000000000
--- a/cpp/167-Two-Sum-II.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-// Window Method
-
-class Solution {
-private:
-
-public:
- vector twoSum(vector& arr, int target) {
- int i = 0, j = arr.size()-1;
-
- while(i < j){
- if(arr[i] + arr[j] == target) return {i+1,j+1};
- if(arr[i] + arr[j] > target) {
- j--;
- }
- else {i++;}
- }
- return {};
- }
-
-};
\ No newline at end of file
diff --git a/cpp/19-Remove-Nth-Node-From-End-of-List.cpp b/cpp/19-Remove-Nth-Node-From-End-of-List.cpp
deleted file mode 100644
index 6927bdde6..000000000
--- a/cpp/19-Remove-Nth-Node-From-End-of-List.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Definition for singly-linked list.
- * struct ListNode {
- * int val;
- * ListNode *next;
- * ListNode() : val(0), next(nullptr) {}
- * ListNode(int x) : val(x), next(nullptr) {}
- * ListNode(int x, ListNode *next) : val(x), next(next) {}
- * };
- */
-class Solution {
-public:
- ListNode* removeNthFromEnd(ListNode* head, int n) {
- if(!head) return head;
- ListNode* f,*s,*prev;
- f=head;
- s=head;
- prev=nullptr;
- for(int i=0;inext;
- while(f)
- {
- prev=s;
- s=s->next;
- f=f->next;
- }
- if(prev)
- prev->next=s->next;
- else
- head=head->next;
- delete s;
- return head;
- }
-};
diff --git a/cpp/20-Valid-Parentheses.cpp b/cpp/20-Valid-Parentheses.cpp
deleted file mode 100644
index 95fa74f8f..000000000
--- a/cpp/20-Valid-Parentheses.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-class Solution {
-public:
- bool isValid(string s) {
- stack stk;
- for(auto a: s) {
- if (a=='(' || a=='{' || a=='[') {
- stk.push(a);
- }
- else {
- if(stk.empty()) return false;
- if( (stk.top() == '(' && a==')') || (stk.top() == '{' && a=='}') || (stk.top() == '[' && a==']') )
- stk.pop();
- else return false;
- }
- }
-
- return stk.empty();
- }
-};
\ No newline at end of file
diff --git a/cpp/202-Happy-Number.cpp b/cpp/202-Happy-Number.cpp
deleted file mode 100644
index c8e4bff1a..000000000
--- a/cpp/202-Happy-Number.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- Time Complexity: O(log n)
- Space Complexity: O(log n)
-*/
-
-class Solution {
-public:
- bool isHappy(int n) {
- unordered_set us;
- while (us.find(n) == us.end()) {
- us.insert(n);
- int temp = 0;
- while (n > 0) {
- int digit = n % 10;
- digit = digit * digit;
- temp += digit;
- n = n / 10;
- }
- n = temp;
- if (n == 1) {
- return true;
- }
- }
- return false;
- }
-};
\ No newline at end of file
diff --git a/cpp/206-Reverse-Linked-List.cpp b/cpp/206-Reverse-Linked-List.cpp
deleted file mode 100644
index fab361fa3..000000000
--- a/cpp/206-Reverse-Linked-List.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * Definition for singly-linked list.
- * struct ListNode {
- * int val;
- * ListNode *next;
- * ListNode() : val(0), next(nullptr) {}
- * ListNode(int x) : val(x), next(nullptr) {}
- * ListNode(int x, ListNode *next) : val(x), next(next) {}
- * };
- */
-class Solution {
-public:
- ListNode* reverseList(ListNode* head) {
- ListNode* rev = new ListNode(0);
- ListNode* ptr = head;
-
- while(ptr) {
- auto temp = ptr;
- ptr=ptr->next;
- temp-> next = rev->next;
- rev->next = temp;
- }
-
- return rev->next;
- }
-};
\ No newline at end of file
diff --git a/cpp/208-Implement-Trie.cpp b/cpp/208-Implement-Trie.cpp
deleted file mode 100644
index 259cf4cce..000000000
--- a/cpp/208-Implement-Trie.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-struct TrieNode {
- TrieNode* children[26];
- bool isWordEnd;
-
- TrieNode() : isWordEnd(false) {
- for (int i = 0; i < 26; ++i)
- children[i] = nullptr;
- }
-};
-
-class Trie {
-private:
- TrieNode* root;
-public:
- Trie() {
- root = new TrieNode;
- }
-
- void insert(string word) {
- TrieNode* cur = root;
-
- int idx;
- for (int i = 0; i < word.size(); ++i) {
- idx = word[i] - 'a';
- if (cur->children[idx] == nullptr)
- cur->children[idx] = new TrieNode;
- cur = cur->children[idx];
- }
- // mark the last node as end of a word
- cur->isWordEnd = true;
- }
-
- bool search(string word) {
- TrieNode* cur = root;
-
- int idx;
- for (int i = 0; i < word.size(); ++i) {
- idx = word[i] - 'a';
- if (cur->children[idx] == nullptr)
- return false;
- cur = cur->children[idx];
- }
- // check if the node is end of any word
- return cur->isWordEnd;
- }
-
- bool startsWith(string prefix) {
- TrieNode* cur = root;
-
- int idx;
- for (int i = 0; i < prefix.size(); ++i) {
- idx = prefix[i] - 'a';
- if (cur->children[idx] == nullptr)
- return false;
- cur = cur->children[idx];
- }
- // only need to check if the node exists
- return true;
- }
-};
diff --git a/cpp/21-Merge-Two-Sorted-Lists.cpp b/cpp/21-Merge-Two-Sorted-Lists.cpp
deleted file mode 100644
index 7e3356fee..000000000
--- a/cpp/21-Merge-Two-Sorted-Lists.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * Definition for singly-linked list.
- * struct ListNode {
- * int val;
- * ListNode *next;
- * ListNode() : val(0), next(nullptr) {}
- * ListNode(int x) : val(x), next(nullptr) {}
- * ListNode(int x, ListNode *next) : val(x), next(next) {}
- * };
- */
-class Solution {
-public:
- ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) {
- ListNode* res = new ListNode(0);
- auto ptr = res;
-
- auto ptr1 = list1;
- auto ptr2 = list2;
-
- while (ptr1 && ptr2) {
- if (ptr1->val < ptr2->val) {
- res->next = ptr1;
- ptr1 = ptr1->next;
- res = res->next;
- }
- else {
- res->next = ptr2;
- ptr2 = ptr2->next;
- res = res->next;
- }
- }
-
- while (ptr1) {
- res->next = ptr1;
- res = res->next;
- ptr1 = ptr1->next;
- }
- while (ptr2) {
- res->next = ptr2;
- res = res->next;
- ptr2 = ptr2->next;
- }
-
- return ptr->next;
- }
-};
\ No newline at end of file
diff --git a/cpp/211-Design-Add-and-Search-Words-Data-Structure.cpp b/cpp/211-Design-Add-and-Search-Words-Data-Structure.cpp
deleted file mode 100644
index 373dea741..000000000
--- a/cpp/211-Design-Add-and-Search-Words-Data-Structure.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-struct TrieNode {
- TrieNode* children[26];
- bool isWordEnd;
-
- TrieNode() : isWordEnd(false) {
- for (int i = 0; i < 26; ++i)
- children[i] = nullptr;
- }
-};
-
-class WordDictionary {
-private:
- TrieNode* root;
-public:
- WordDictionary() {
- root = new TrieNode;
- }
-
- void addWord(string word) {
- // simple trie insertion
- TrieNode* cur = root;
-
- int idx;
- for (int i = 0; i < word.size(); ++i) {
- idx = word[i] - 'a';
- if (cur->children[idx] == nullptr)
- cur->children[idx] = new TrieNode;
- cur = cur->children[idx];
- }
- // mark the last node as end of a word
- cur->isWordEnd = true;
- }
-
- bool recursiveSearch(const string &word, int curIdx, const TrieNode *node) {
- auto cur = node;
-
- for (int i = curIdx; i < word.size(); ++i) {
- if (word[i] == '.') {
- // can match any character - backtracking is required
- for (int j = 0; j < 26; ++j) {
- if (cur->children[j] == nullptr) // skip non-existing characters
- continue;
- if (recursiveSearch(word, i + 1, cur->children[j])) // try and backtrack if fails
- return true;
- }
- // search with backtracking failed in all children
- return false;
- }
- else {
- // simple trie search
- int idx = word[i] - 'a';
- if (cur->children[idx] == nullptr)
- return false;
- cur = cur->children[idx];
- }
- }
- // check if the node is end of any word
- return cur->isWordEnd;
- }
-
- bool search(string word) {
- return recursiveSearch(word, 0, root);
- }
-};
diff --git a/cpp/212-Word-Search-II.cpp b/cpp/212-Word-Search-II.cpp
deleted file mode 100644
index f3283dbbd..000000000
--- a/cpp/212-Word-Search-II.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-struct TrieNode {
- TrieNode* children[26];
- int wordEndCnt;
- string word;
-
- TrieNode() : wordEndCnt(0), word("") {
- for (int i = 0; i < 26; ++i)
- children[i] = nullptr;
- }
-};
-
-class Solution {
-public:
- void addWord(TrieNode* node, const string& word) {
- // simple trie insertion
- TrieNode* cur = node;
-
- int idx;
- for (int i = 0; i < word.size(); ++i) {
- idx = word[i] - 'a';
- if (cur->children[idx] == nullptr)
- cur->children[idx] = new TrieNode;
- cur = cur->children[idx];
- }
- // increase the word end counter
- ++cur->wordEndCnt;
- cur->word = word;
- }
-
- void solve(vector>& board, int ROWS, int COLS, int r, int c, vector& result, TrieNode* cur) {
- // boundary check
- if (r < 0 || r >= ROWS || c < 0 || c >= COLS)
- return;
- // visit check
- if (board[r][c] == '$')
- return;
- // existence check
- int idx = board[r][c] - 'a';
- if (cur->children[idx] == nullptr)
- return;
- cur = cur->children[idx];
- if (cur->wordEndCnt > 0) {
- // found word
- result.push_back(cur->word);
- --cur->wordEndCnt;
- }
-
- // mark as visited and backtrack
- char origin = board[r][c];
- board[r][c] = '$';
- solve(board, ROWS, COLS, r + 1, c, result, cur);
- solve(board, ROWS, COLS, r - 1, c, result, cur);
- solve(board, ROWS, COLS, r, c + 1, result, cur);
- solve(board, ROWS, COLS, r, c - 1, result, cur);
- board[r][c] = origin;
- }
-
- vector findWords(vector>& board, vector& words) {
- TrieNode* root = new TrieNode;
- for (auto w : words) {
- addWord(root, w);
- }
- int ROWS = board.size(), COLS = board[0].size();
-
- vector result;
- // check every cells
- for (int i = 0; i < ROWS; ++i)
- for (int j = 0; j < COLS; ++j)
- solve(board, ROWS, COLS, i, j, result, root);
- return result;
- }
-};
diff --git a/cpp/215-Kth-Largest-Element-in-an-Array.cpp b/cpp/215-Kth-Largest-Element-in-an-Array.cpp
deleted file mode 100644
index 0e9518fb4..000000000
--- a/cpp/215-Kth-Largest-Element-in-an-Array.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-class Solution {
-public:
- int findKthLargest(vector& nums, int k) {
- priority_queue, greater> pq(nums.begin(), nums.end());
- while (pq.size() > k)pq.pop();
- return pq.top();
- }
-};
\ No newline at end of file
diff --git a/cpp/217-Contains-Duplicate.cpp b/cpp/217-Contains-Duplicate.cpp
deleted file mode 100644
index e5b6b312b..000000000
--- a/cpp/217-Contains-Duplicate.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-class Solution {
-public:
- bool containsDuplicate(vector& nums) {
- unordered_set s;
- for(auto n: nums){
- if(s.find(n) != s.end()) return true;
-
- s.insert(n);
- }
-
- return false;
- }
-};
\ No newline at end of file
diff --git a/cpp/226-Invert-Binary-Tree.cpp b/cpp/226-Invert-Binary-Tree.cpp
deleted file mode 100644
index f17dd876d..000000000
--- a/cpp/226-Invert-Binary-Tree.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * Definition for a binary tree node.
- * struct TreeNode {
- * int val;
- * TreeNode *left;
- * TreeNode *right;
- * TreeNode() : val(0), left(nullptr), right(nullptr) {}
- * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
- * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
- * };
- */
-class Solution {
-public:
- TreeNode* invertTree(TreeNode* root) {
- if (root == NULL) return root;
- auto ptr = root;
- auto temp = ptr->left;
- ptr->left = ptr->right;
- ptr->right = temp;
-
- invertTree(ptr->left);
- invertTree(ptr->right);
-
- return root;
- }
-};
\ No newline at end of file
diff --git a/cpp/238-Product-of-Array-Except-Self.cpp b/cpp/238-Product-of-Array-Except-Self.cpp
deleted file mode 100644
index 6e4215ed0..000000000
--- a/cpp/238-Product-of-Array-Except-Self.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-class Solution {
-public:
- vector productExceptSelf(vector& nums) {
- int n = nums.size();
- vector res(n);
-
- // compute with prefix
- int prefix = 1;
- for (int i = 0; i < n; ++i) {
- res[i] = prefix;
- prefix *= nums[i];
- }
- // compute with posfix
- int postfix = 1;
- for (int i = n-1; i >= 0; --i) {
- res[i] *= postfix;
- postfix *= nums[i];
- }
- return res;
- }
-};
diff --git a/cpp/242-Valid-Anagram.cpp b/cpp/242-Valid-Anagram.cpp
deleted file mode 100644
index 4c0f57eb2..000000000
--- a/cpp/242-Valid-Anagram.cpp
+++ /dev/null
@@ -1,10 +0,0 @@
-class Solution {
-public:
- bool isAnagram(string s, string t) {
- vector count(26, 0);
- for (auto a: s) count[a-'a']++;
- for (auto a: t) count[a-'a']--;
- for (auto c: count) if(c) return false;
- return true;
- }
-};
\ No newline at end of file
diff --git a/cpp/268-Missing-Number.cpp b/cpp/268-Missing-Number.cpp
deleted file mode 100644
index c5be409d8..000000000
--- a/cpp/268-Missing-Number.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-class Solution {
-public:
- int missingNumber(vector& nums) {
- int sum=0;
- int n=nums.size();
- for(auto num: nums)
- sum+=num;
-
- return n*(n+1)/2 - sum;
- }
-};
\ No newline at end of file
diff --git a/cpp/3-Longest-Substring-Without-Repeating-Characters.cpp b/cpp/3-Longest-Substring-Without-Repeating-Characters.cpp
deleted file mode 100644
index 62d3f22dc..000000000
--- a/cpp/3-Longest-Substring-Without-Repeating-Characters.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-class Solution {
-public:
- int lengthOfLongestSubstring(string s) {
- if(s.length()==1)
- return 1;
-
- int j,max=0,count=0,found;
- string ss="";
- for(j=0;j& nums, int target) {
- int start = 0, end = nums.size() - 1;
- while(start <= end){
- int mid = start + (end - start) / 2;
- if(nums[mid] == target)
- return mid;
- else if(nums[mid] >= nums[start]){
- if(target >= nums[start] && target < nums[mid])
- end = mid - 1;
- else
- start = mid + 1;
- }else{
- if(target > nums[mid] && target <= nums[end])
- start = mid + 1;
- else
- end = mid - 1;
- }
- }
- return -1;
- }
-};
diff --git a/cpp/347-Top-K-Frequent-Elements.cpp b/cpp/347-Top-K-Frequent-Elements.cpp
deleted file mode 100644
index 578068eaf..000000000
--- a/cpp/347-Top-K-Frequent-Elements.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-class Solution {
-public:
- vector topKFrequent(vector& nums, int k) {
- unordered_map count;
- for (int n : nums) {
- ++count[n];
- }
-
- vector> freq(nums.size() + 1, vector());
- for (auto e : count) {
- freq[e.second].push_back(e.first);
- }
-
- vector result;
- for (int i = freq.size()-1; i >= 0; --i) {
- for (int n : freq[i]) {
- result.push_back(n);
- if (result.size() == k)
- return result;
- }
- }
- return result;
- }
-};
diff --git a/cpp/36-Valid-Sudoku.cpp b/cpp/36-Valid-Sudoku.cpp
deleted file mode 100644
index fc4041f38..000000000
--- a/cpp/36-Valid-Sudoku.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-class Solution {
-public:
- bool isValidSudoku(vector>& board) {
-
- unordered_set row[9];
- unordered_set col[9];
- unordered_set squ[3][3];
-
- for(int i=0;i<9;i++)
- for(int j=0;j<9;j++)
- {
- if (board[i][j]=='.')
- continue;
- else if(row[i].find(board[i][j]) !=row[i].end()
- || col[j].find(board[i][j]) !=col[j].end()
- || squ[i/3][j/3].find(board[i][j]) !=squ[i/3][j/3].end()
- )
- return false;
- else
- {
- row[i].insert(board[i][j]);
- col[j].insert(board[i][j]);
- squ[i/3][j/3].insert(board[i][j]);
-
- }
- }
- return 1;}
-};
diff --git a/cpp/42-Trapping-Rain-Water.cpp b/cpp/42-Trapping-Rain-Water.cpp
deleted file mode 100644
index fb150d7ae..000000000
--- a/cpp/42-Trapping-Rain-Water.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-class Solution {
-public:
- int trap(vector& height) {
- int left=0,right=height.size()-1,leftmax=0,rightmax=0,ans=0;
- while(leftheight[left]){
- ans+=leftmax-height[left];
- left++;
- continue;
- }else {
- leftmax=height[left];
- }
- if(rightmax>height[right]){
-
- ans+=(rightmax-height[right]);
- right--;
- continue;
- }else {
- rightmax=height[right];
- }
-
- if(leftmax> groupAnagrams(vector& strs) {
- unordered_map> hash;
-
- for (string &s : strs) {
- string key = s;
- sort(key.begin(), key.end()); // klogk * n
- hash[key].push_back(s);
- }
-
- vector> result;
- for (auto &entry : hash) {
- result.push_back(entry.second);
- }
-
- return result;
- }
-};
diff --git a/cpp/543-Diameter-of-Binary-Tree.cpp b/cpp/543-Diameter-of-Binary-Tree.cpp
deleted file mode 100644
index 32dd4fb8c..000000000
--- a/cpp/543-Diameter-of-Binary-Tree.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * Definition for a binary tree node.
- * struct TreeNode {
- * int val;
- * TreeNode *left;
- * TreeNode *right;
- * TreeNode() : val(0), left(nullptr), right(nullptr) {}
- * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
- * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
- * };
- */
-class Solution {
-public:
-
- int MaxHeight(TreeNode* root, int& res) {
- if (root == NULL) return 0;
- int l = MaxHeight(root->left, res);
- int r = MaxHeight(root->right, res);
- res = max(res, max(max(l, r), l + r));
- return 1 + max(l, r);
- }
-
- int diameterOfBinaryTree(TreeNode* root) {
- int breadth = 0;
- MaxHeight(root, breadth);
- return breadth;
- }
-};
\ No newline at end of file
diff --git a/cpp/70-Climbing-Stairs.cpp b/cpp/70-Climbing-Stairs.cpp
deleted file mode 100644
index 0e8702b74..000000000
--- a/cpp/70-Climbing-Stairs.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-class Solution {
-public:
- int dp[50];
- int recur(int n)
- {
- if(n<=3)
- return n ;
- if(dp[n]!=-1)
- return dp[n];
- int op1=recur(n-1);
- int op2=recur(n-2);
- return dp[n]=op1+op2;
- }
- int climbStairs(int n) {
- memset(dp,-1,sizeof dp);
- return recur(n);
- }
-};
diff --git a/cpp/703-Kth-Largest-Element-in-a-Stream.cpp b/cpp/703-Kth-Largest-Element-in-a-Stream.cpp
deleted file mode 100644
index 884d7ce63..000000000
--- a/cpp/703-Kth-Largest-Element-in-a-Stream.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-class KthLargest {
-public:
- priority_queue, greater> pq;
- int k;
- KthLargest(int k, vector& nums) {
- this->k = k;
- for (auto a: nums) pq.push(a);
- while(pq.size()>k){
- pq.pop();
- }
- }
-
- int add(int val) {
- pq.push(val);
- while(pq.size()>k){
- pq.pop();
- }
- return pq.top();
- }
-};
-
-/**
- * Your KthLargest object will be instantiated and called as such:
- * KthLargest* obj = new KthLargest(k, nums);
- * int param_1 = obj->add(val);
- */
\ No newline at end of file
diff --git a/cpp/704-Binary-Search.cpp b/cpp/704-Binary-Search.cpp
deleted file mode 100644
index 643151ef5..000000000
--- a/cpp/704-Binary-Search.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-class Solution {
-public:
- int search(vector& nums, int target) {
- int n = nums.size();
- if (nums[0] == target) return 0;
- if (nums[n-1] == target) return n-1;
-
- int start = 0, end = n-1;
-
- while (start < end) {
- int mid = start + (end-start)/2;
- if (nums[mid] == target) return mid;
- if (nums[mid] > target) {
- end = mid;
- }
- else {
- start = mid + 1;
- }
- }
-
- return -1;
- }
-};
\ No newline at end of file
diff --git a/cpp/74-Search-a-2d-matrix.cpp b/cpp/74-Search-a-2d-matrix.cpp
deleted file mode 100644
index bd36d88ea..000000000
--- a/cpp/74-Search-a-2d-matrix.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-// OJ: https://leetcode.com/problems/search-a-2d-matrix/
-// Time: O(M + N)
-// Space: O(1)
-class Solution {
-public:
- bool searchMatrix(vector>& A, int target) {
- if (A.empty() || A[0].empty()) return false;
- int M = A.size(), N = A[0].size(), i = 0, j = N - 1;
- while (i < M && j >= 0) {
- if (A[i][j] == target) return true;
- if (A[i][j] < target) ++i;
- else --j;
- }
- return false;
- }
-};
diff --git a/cpp/746-Min-Cost-Climbing-Stairs.cpp b/cpp/746-Min-Cost-Climbing-Stairs.cpp
deleted file mode 100644
index cffbb45f0..000000000
--- a/cpp/746-Min-Cost-Climbing-Stairs.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-class Solution {
-public:
- int minCostClimbingStairs(vector& cost) {
- int n=cost.size();
- int i;
- int dp[n+1];
- dp[0]=cost[0];
- dp[1]=cost[1];
- for(i=2;i<=n;i++)
- {
- dp[i]=min(dp[i-1],dp[i-2])+(i==n?0:cost[i]);
- }
-
- return dp[n];
- }
-};
diff --git a/cpp/973-K-Closest-Points-to-Origin.cpp b/cpp/973-K-Closest-Points-to-Origin.cpp
deleted file mode 100644
index 3cff91967..000000000
--- a/cpp/973-K-Closest-Points-to-Origin.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-class Solution {
-public:
- struct cords {
- int x, y;
- cords(vector a) {
- this -> x = a[0];
- this -> y = a[1];
- }
- cords(int x, int y){
- this -> x = x;
- this -> y = y;
- }
- int dist(){
- return x*x+y*y;
- }
- };
-
- struct compare {
- bool operator()(cords a, cords b) {
- return a.dist() < b.dist();
- }
- };
-
- vector> kClosest(vector>& points, int k) {
- priority_queue, compare> pq;
- for (auto a: points) {
- pq.push(cords(a));
- }
-
- while (pq.size() > k) pq.pop();
-
- vector> res;
- while (!pq.empty()) {
- res.push_back({pq.top().x, pq.top().y});
- pq.pop();
- }
- return res;
- }
-};
\ No newline at end of file
diff --git a/cpp/98-Validate-Binary-Search-Tree.cpp b/cpp/98-Validate-Binary-Search-Tree.cpp
deleted file mode 100644
index 6f6b25157..000000000
--- a/cpp/98-Validate-Binary-Search-Tree.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * Definition for a binary tree node.
- * struct TreeNode {
- * int val;
- * TreeNode *left;
- * TreeNode *right;
- * TreeNode() : val(0), left(nullptr), right(nullptr) {}
- * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
- * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
- * };
- */
-void check(TreeNode* root,vector& v)
- {
- if(!root) return;
- check(root->left,v);
- v.push_back(root->val);
- check(root->right,v);
-}
-class Solution {
-public:
- bool isValidBST(TreeNode* root) {
- vector v;
- check(root,v);
- for(int i=0;i=v[i+1])
- return 0;
- }
- return 1;
- }
-};
diff --git a/csharp/1-ArraysAndHashing/main/1_ArrayAndHashing.csproj b/csharp/1-ArraysAndHashing/main/1_ArrayAndHashing.csproj
new file mode 100644
index 000000000..d2b0a5fab
--- /dev/null
+++ b/csharp/1-ArraysAndHashing/main/1_ArrayAndHashing.csproj
@@ -0,0 +1,10 @@
+
+
+
+ net8.0
+ enable
+ enable
+ false
+
+
+
diff --git a/csharp/1-ArraysAndHashing/main/N1-L217-ContainsDuplicate/Solution.cs b/csharp/1-ArraysAndHashing/main/N1-L217-ContainsDuplicate/Solution.cs
new file mode 100644
index 000000000..3cb20ccd2
--- /dev/null
+++ b/csharp/1-ArraysAndHashing/main/N1-L217-ContainsDuplicate/Solution.cs
@@ -0,0 +1,18 @@
+namespace ArrayAndHashing.Main.ContainsDuplicate
+{
+ public class Solution
+ {
+ public bool ContainsDuplicate(int[] nums)
+ {
+ HashSet seenNums = new();
+ foreach (var item in nums)
+ {
+ if (seenNums.Contains(item))
+ return true;
+ seenNums.Add(item);
+ }
+
+ return false;
+ }
+ }
+}
diff --git a/csharp/1-ArraysAndHashing/main/N1-L217-ContainsDuplicate/readme.md b/csharp/1-ArraysAndHashing/main/N1-L217-ContainsDuplicate/readme.md
new file mode 100644
index 000000000..6fc1e68c8
--- /dev/null
+++ b/csharp/1-ArraysAndHashing/main/N1-L217-ContainsDuplicate/readme.md
@@ -0,0 +1,26 @@
+# N1-L217. Contains duplicate
+
+https://leetcode.com/problems/contains-duplicate/
+
+Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.
+
+## Example 1:
+
+Input: nums = [1,2,3,1]
+Output: true
+
+## Example 2:
+
+Input: nums = [1,2,3,4]
+Output: false
+
+## Example 3:
+
+Input: nums = [1,1,1,3,3,4,3,2,4,2]
+Output: true
+
+## Constraints:
+
+ 1 <= nums.length <= 105
+ -109 <= nums[i] <= 109
+
diff --git a/csharp/1-ArraysAndHashing/main/N2-L242-ValidAnagram/Solution.cs b/csharp/1-ArraysAndHashing/main/N2-L242-ValidAnagram/Solution.cs
new file mode 100644
index 000000000..821222a26
--- /dev/null
+++ b/csharp/1-ArraysAndHashing/main/N2-L242-ValidAnagram/Solution.cs
@@ -0,0 +1,64 @@
+namespace ArrayAndHashing.Main.Validanagram
+{
+ public class Solution
+ {
+ public bool IsAnagram(string s, string t)
+ {
+ if (s.Length != t.Length)
+ return false;
+
+ Dictionary sDict = new();
+ Dictionary tDict = new();
+ for (int i = 0; i < s.Length; i++)
+ {
+ char sChar = s[i];
+ char tChar = t[i];
+ sDict = UpdateCharacterDictionary(sDict, sChar);
+ tDict = UpdateCharacterDictionary(tDict, tChar);
+ }
+
+ return AreDictsEqual(sDict, tDict);
+ }
+
+ private bool AreDictsEqual(Dictionary sDict, Dictionary tDict)
+ {
+ bool areEqual = true;
+ if (sDict.Count != tDict.Count)
+ return false;
+
+ foreach (var sDictPair in sDict)
+ {
+ int tValue;
+ if (tDict.TryGetValue(sDictPair.Key, out tValue))
+ {
+ // because all values must be the same in both dicts
+ if (tValue != sDictPair.Value)
+ {
+ areEqual = false;
+ break;
+ }
+ }
+ else
+ {
+ // because all keys of sDict must be present in tDcit
+ areEqual = false;
+ break;
+ }
+ }
+
+ return areEqual;
+ }
+
+ private static Dictionary UpdateCharacterDictionary(Dictionary aDict, char aChar)
+ {
+ if (aDict.ContainsKey(aChar))
+ aDict[aChar]++;
+ else
+ {
+ aDict[aChar] = 1;
+ }
+
+ return aDict;
+ }
+ }
+}
\ No newline at end of file
diff --git a/csharp/1-ArraysAndHashing/main/N2-L242-ValidAnagram/readme.md b/csharp/1-ArraysAndHashing/main/N2-L242-ValidAnagram/readme.md
new file mode 100644
index 000000000..86f095dd3
--- /dev/null
+++ b/csharp/1-ArraysAndHashing/main/N2-L242-ValidAnagram/readme.md
@@ -0,0 +1,24 @@
+# N2-L242. Valid Anagram
+
+https://leetcode.com/problems/valid-anagram/
+
+Given two strings s and t, return true if t is an anagram of s, and false otherwise.
+
+An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
+
+## Example 1:
+
+Input: s = "anagram", t = "nagaram"
+Output: true
+
+## Example 2:
+
+Input: s = "rat", t = "car"
+Output: false
+
+## Constraints:
+1 <= s.length, t.length <= 5 * 104
+s and t consist of lowercase English letters.
+
+## Follow up
+What if the inputs contain Unicode characters? How would you adapt your solution to such a case?
diff --git a/csharp/1-ArraysAndHashing/main/N3-L1-TwoSum/Solution.cs b/csharp/1-ArraysAndHashing/main/N3-L1-TwoSum/Solution.cs
new file mode 100644
index 000000000..d3205de0d
--- /dev/null
+++ b/csharp/1-ArraysAndHashing/main/N3-L1-TwoSum/Solution.cs
@@ -0,0 +1,56 @@
+namespace ArrayAndHashing.Main.TwoSum
+{
+ public class Solution
+ {
+
+ // time complexity : O(n^2)
+ // space complexity : O(2n)
+ // where n = nums.Length
+ public int[] TwoSumN2(int[] nums, int target)
+ {
+ int[] retval = new int[2];
+ for (int i = 0; i < nums.Length; i++)
+ {
+ for (int j = i + 1; j < nums.Length; j++)
+ {
+ if (nums[i] + nums[j] == target)
+ {
+ retval[0] = i;
+ retval[1] = j;
+ break;
+ }
+ }
+ // retval[1] is never 0 in a successful sum
+ if (retval[1] != 0)
+ break;
+ }
+ return retval;
+ }
+
+ // time complexity : O(n) = only one for loop +
+ // in a Dictionary retrieval time by key is O(1)
+ // space complexity : O(n) = the size of the dictionary
+ public int[] TwoSum(int[] nums, int target)
+ {
+ int[] retval = new int[2];
+ Dictionary map = new();
+ for (int i = 0; i < nums.Length; i++)
+ {
+ int current_elem = nums[i];
+ int diff = target - current_elem;
+ if (map.ContainsKey(diff))
+ {
+ retval[0] = map[diff];
+ retval[1] = i;
+ break;
+ }
+ // you may have repeated elements in nums, see test case 4
+ if (!map.ContainsKey(current_elem))
+ map.Add(current_elem, i);
+ }
+ return retval;
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/csharp/1-ArraysAndHashing/main/N3-L1-TwoSum/readme.md b/csharp/1-ArraysAndHashing/main/N3-L1-TwoSum/readme.md
new file mode 100644
index 000000000..a3a08236d
--- /dev/null
+++ b/csharp/1-ArraysAndHashing/main/N3-L1-TwoSum/readme.md
@@ -0,0 +1,34 @@
+# N3-L1. Two Sum
+
+Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
+
+You may assume that each input would have exactly one solution, and you may not use the same element twice.
+
+You can return the answer in any order.
+
+## Example 1:
+
+Input: nums = [2,7,11,15], target = 9
+Output: [0,1]
+Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
+
+## Example 2:
+
+Input: nums = [3,2,4], target = 6
+Output: [1,2]
+
+## Example 3:
+
+Input: nums = [3,3], target = 6
+Output: [0,1]
+
+## Constraints:
+
+ 2 <= nums.length <= 104
+ -109 <= nums[i] <= 109
+ -109 <= target <= 109
+ Only one valid answer exists.
+
+
+## Follow-up
+Can you come up with an algorithm that is less than O(n2) time complexity?
\ No newline at end of file
diff --git a/csharp/1-ArraysAndHashing/testCases/1_ArrayAndHashingTest.csproj b/csharp/1-ArraysAndHashing/testCases/1_ArrayAndHashingTest.csproj
new file mode 100644
index 000000000..ccacc2895
--- /dev/null
+++ b/csharp/1-ArraysAndHashing/testCases/1_ArrayAndHashingTest.csproj
@@ -0,0 +1,21 @@
+
+
+
+ net8.0
+ enable
+
+
+ false
+ false
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/csharp/1-ArraysAndHashing/testCases/N1-L217-ContainsDuplicate_Test.cs b/csharp/1-ArraysAndHashing/testCases/N1-L217-ContainsDuplicate_Test.cs
new file mode 100644
index 000000000..445726dac
--- /dev/null
+++ b/csharp/1-ArraysAndHashing/testCases/N1-L217-ContainsDuplicate_Test.cs
@@ -0,0 +1,46 @@
+using NUnit.Framework;
+using ArrayAndHashing.Main.ContainsDuplicate;
+using FluentAssertions;
+
+namespace testCases;
+
+public class ContainsDuplicate_Test
+{
+ [Test]
+ public void TestCase_1()
+ {
+ // Arrange
+ int[] input = { 1, 2, 3, 1 };
+
+ // Act
+ Solution solution = new Solution();
+ bool testResult = solution.ContainsDuplicate(input);
+
+ // Assert
+ testResult.Should().Be(true);
+ }
+
+ [Test]
+ public void TestCase_2()
+ {
+ int[] input = { 1, 2, 3, 4 };
+
+ // Act
+ Solution solution = new Solution();
+ bool testResult = solution.ContainsDuplicate(input);
+
+ // Assert
+ testResult.Should().Be(false);
+ }
+
+ [Test]
+ public void TestCase_3()
+ {
+ int[] input = { 1, 1, 1, 3, 3, 4, 3, 2, 4, 2 };
+
+ Solution solution = new Solution();
+ bool testResult = solution.ContainsDuplicate(input);
+
+ testResult.Should().Be(true);
+ }
+}
\ No newline at end of file
diff --git a/csharp/1-ArraysAndHashing/testCases/N2-L242-ValidAnagram_Test.cs b/csharp/1-ArraysAndHashing/testCases/N2-L242-ValidAnagram_Test.cs
new file mode 100644
index 000000000..117cc3bac
--- /dev/null
+++ b/csharp/1-ArraysAndHashing/testCases/N2-L242-ValidAnagram_Test.cs
@@ -0,0 +1,53 @@
+using ArrayAndHashing.Main.Validanagram;
+using FluentAssertions;
+using NUnit.Framework;
+
+namespace testCases
+{
+ public class ValidAnagram_Test
+ {
+
+ [Test]
+ public void Test_Example_1()
+ {
+ // Arrange
+ string s = "anagram";
+ string t = "nagaram";
+
+ // Act
+ Solution solution = new Solution();
+ bool testResult = solution.IsAnagram(s,t);
+
+ // Assert
+ testResult.Should().Be(true);
+ }
+
+ [Test]
+ public void Test_Example_2()
+ {
+ // Arrange
+ string s = "rat";
+ string t = "car";
+
+ // Act
+ Solution solution = new Solution();
+ bool testResult = solution.IsAnagram(s, t);
+
+ // Assert
+ testResult.Should().Be(false);
+ }
+
+ [Test]
+ public void Test_Example_3()
+ {
+ string s = "aacc";
+ string t = "ccac";
+
+ Solution solution = new Solution();
+ bool testResult = solution.IsAnagram(s, t);
+
+ // Assert
+ testResult.Should().Be(false);
+ }
+ }
+}
\ No newline at end of file
diff --git a/csharp/1-ArraysAndHashing/testCases/N3-L1-TwoSum_Test.cs b/csharp/1-ArraysAndHashing/testCases/N3-L1-TwoSum_Test.cs
new file mode 100644
index 000000000..aee4c33fc
--- /dev/null
+++ b/csharp/1-ArraysAndHashing/testCases/N3-L1-TwoSum_Test.cs
@@ -0,0 +1,65 @@
+using ArrayAndHashing.Main.TwoSum;
+using FluentAssertions;
+using NUnit.Framework;
+
+namespace testCases
+{
+ public class TwoSum_Test
+ {
+ [Test]
+ public void Test_Example_1()
+ {
+ int[] nums = { 2, 7, 11, 15 };
+ int target = 9;
+
+ Solution solution = new Solution();
+ int[] testResult = solution.TwoSum(nums, target);
+
+ testResult[0].Should().Be(0);
+ testResult[1].Should().Be(1);
+
+ }
+
+ [Test]
+ public void Test_Example_2()
+ {
+ int[] nums = { 3, 2, 4 };
+ int target = 6;
+
+ Solution solution = new Solution();
+ int[] testResult = solution.TwoSum(nums, target);
+
+ testResult[0].Should().Be(1);
+ testResult[1].Should().Be(2);
+ }
+
+ [Test]
+ public void Test_Example_3()
+ {
+ int[] nums = { 3, 3 };
+ int target = 6;
+
+ Solution solution = new Solution();
+ int[] testResult = solution.TwoSum(nums, target);
+
+ testResult[0].Should().Be(0);
+ testResult[1].Should().Be(1);
+
+ }
+
+ [Test]
+ public void Test_Example_4()
+ {
+ int[] nums = { 1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 7, 1, 1, 1, 1, 1 };
+ int target = 11;
+
+ Solution solution = new Solution();
+ int[] testResult = solution.TwoSum(nums, target);
+
+ testResult[0].Should().Be(5);
+ testResult[1].Should().Be(11);
+
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/csharp/11-Graphs/main/11_Graphs.csproj b/csharp/11-Graphs/main/11_Graphs.csproj
new file mode 100644
index 000000000..31849decd
--- /dev/null
+++ b/csharp/11-Graphs/main/11_Graphs.csproj
@@ -0,0 +1,10 @@
+
+
+
+ net8.0
+ enable
+ enable
+ false
+
+
+
diff --git a/csharp/11-Graphs/main/N1-L200-NumberOfIslands/Solution.cs b/csharp/11-Graphs/main/N1-L200-NumberOfIslands/Solution.cs
new file mode 100644
index 000000000..0b0a85ac4
--- /dev/null
+++ b/csharp/11-Graphs/main/N1-L200-NumberOfIslands/Solution.cs
@@ -0,0 +1,16 @@
+namespace Graphs.Main.NumberOfIslands
+{
+ public class Solution
+ {
+ public int NumIslands(char[][] grid)
+ {
+ if (grid is null)
+ return 0;
+
+ int nrIsland = 0;
+ HashSet visited = new();
+
+ return 0;
+ }
+ }
+}
\ No newline at end of file
diff --git a/csharp/11-Graphs/main/N1-L200-NumberOfIslands/readme.md b/csharp/11-Graphs/main/N1-L200-NumberOfIslands/readme.md
new file mode 100644
index 000000000..4122a9990
--- /dev/null
+++ b/csharp/11-Graphs/main/N1-L200-NumberOfIslands/readme.md
@@ -0,0 +1,34 @@
+# 200. Number of Islands
+
+Medium
+
+Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands.
+
+An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.
+
+## Example 1
+
+Input: grid = [
+ ["1","1","1","1","0"],
+ ["1","1","0","1","0"],
+ ["1","1","0","0","0"],
+ ["0","0","0","0","0"]
+]
+Output: 1
+
+## Example 2
+
+Input: grid = [
+ ["1","1","0","0","0"],
+ ["1","1","0","0","0"],
+ ["0","0","1","0","0"],
+ ["0","0","0","1","1"]
+]
+Output: 3
+
+## Constraints :
+
+ m == grid.length
+ n == grid[i].length
+ 1 <= m, n <= 300
+ grid[i][j] is '0' or '1'.
diff --git a/csharp/11-Graphs/testCases/11_GraphTests.csproj b/csharp/11-Graphs/testCases/11_GraphTests.csproj
new file mode 100644
index 000000000..ffc5de19a
--- /dev/null
+++ b/csharp/11-Graphs/testCases/11_GraphTests.csproj
@@ -0,0 +1,22 @@
+
+
+
+ net8.0
+ enable
+ false
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/csharp/11-Graphs/testCases/N1-L200-NumberOfIslands_Test.cs b/csharp/11-Graphs/testCases/N1-L200-NumberOfIslands_Test.cs
new file mode 100644
index 000000000..ff6d0c543
--- /dev/null
+++ b/csharp/11-Graphs/testCases/N1-L200-NumberOfIslands_Test.cs
@@ -0,0 +1,24 @@
+using FluentAssertions;
+using Graphs.Main.NumberOfIslands;
+using NUnit.Framework;
+
+namespace testCases;
+
+public class NumberOfIsland_Test
+{
+ [Test]
+ public void Example_Test_1()
+ {
+ char[][] inputGrid = new char[][] {
+ new char[] {'1', '1', '1', '1', '0'},
+ new char[] {'1', '1', '0', '0', '0'},
+ new char[] {'0', '0', '1', '0', '0'},
+ new char[] {'0', '0', '0', '1', '1'}
+ };
+
+ Solution solution = new();
+ int testOutput = solution.NumIslands(inputGrid);
+
+ testOutput.Should().Be(3);
+ }
+}
\ No newline at end of file
diff --git a/csharp/11_BackTracking/11_BackTracking.csproj b/csharp/11_BackTracking/11_BackTracking.csproj
new file mode 100644
index 000000000..9bc584a5a
--- /dev/null
+++ b/csharp/11_BackTracking/11_BackTracking.csproj
@@ -0,0 +1,10 @@
+
+
+
+ net8.0
+ _11_BackTracking
+ enable
+ enable
+
+
+
diff --git a/csharp/11_BackTracking/L1863_SumOfAllSubsetsXorTotal/Solution.cs b/csharp/11_BackTracking/L1863_SumOfAllSubsetsXorTotal/Solution.cs
new file mode 100644
index 000000000..a07e90b37
--- /dev/null
+++ b/csharp/11_BackTracking/L1863_SumOfAllSubsetsXorTotal/Solution.cs
@@ -0,0 +1,28 @@
+namespace _11_BackTracking.L1863_SumOfAllSubsetsXorTotal;
+
+public class Solution {
+
+ // Time complexity: O(2^N)
+ // Space complexity: O(N)
+ public int SubsetXORSum(int[] nums)
+ {
+ var result = 0;
+
+ return depthFirstSearch(0, 0);
+
+ int depthFirstSearch(int i, int total)
+ {
+ result += total;
+
+ if (i == nums.Length)
+ return total;
+
+ var sumIncludingCurrentElement = depthFirstSearch(i+1, nums[i] ^ total);
+ var sumExcludingCurrentElement = depthFirstSearch(i+1, total);
+
+ return sumIncludingCurrentElement + sumExcludingCurrentElement;
+ }
+ }
+
+
+}
\ No newline at end of file
diff --git a/csharp/11_BackTracking/L1863_SumOfAllSubsetsXorTotal/readme.md b/csharp/11_BackTracking/L1863_SumOfAllSubsetsXorTotal/readme.md
new file mode 100644
index 000000000..235d029bf
--- /dev/null
+++ b/csharp/11_BackTracking/L1863_SumOfAllSubsetsXorTotal/readme.md
@@ -0,0 +1,58 @@
+# Sum of all subsets XOR Total
+
+The XOR total of an array is defined as the bitwise XOR of all its elements, or 0 if the array is empty.
+
+For example, the XOR total of the array [2,5,6] is 2 XOR 5 XOR 6 = 1 :
+
+2 010
+5 101
+2 XOR 5 111
+6 110
+2 XOR 5 XOR 6 001
+
+Given an array nums, return the sum of all XOR totals for every subset of nums.
+
+Note: Subsets with the same elements should be counted multiple times.
+
+An array a is a subset of an array b if a can be obtained from b by deleting some (possibly zero) elements of b.
+
+
+### Example 1
+
+Input: nums = [1,3]
+Output: 6
+Explanation: The 4 subsets of [1,3] are:
+- The empty subset has an XOR total of 0.
+- [1] has an XOR total of 1.
+- [3] has an XOR total of 3.
+- [1,3] has an XOR total of 1 XOR 3 = 2.
+ 0 + 1 + 3 + 2 = 6
+
+### Example 2
+
+Input: nums = [5,1,6]
+Output: 28
+Explanation: The 8 subsets of [5,1,6] are:
+- The empty subset has an XOR total of 0.
+- [5] has an XOR total of 5.
+- [1] has an XOR total of 1.
+- [6] has an XOR total of 6.
+- [5,1] has an XOR total of 5 XOR 1 = 4.
+- [5,6] has an XOR total of 5 XOR 6 = 3.
+- [1,6] has an XOR total of 1 XOR 6 = 7.
+- [5,1,6] has an XOR total of 5 XOR 1 XOR 6 = 2.
+ 0 + 5 + 1 + 6 + 4 + 3 + 7 + 2 = 28
+
+### Example 3
+
+Input: nums = [3,4,5,6,7,8]
+Output: 480
+Explanation: The sum of all XOR totals for every subset is 480.
+
+
+
+Constraints:
+
+ 1 <= nums.length <= 12
+ 1 <= nums[i] <= 20
+
diff --git a/csharp/11_BackTracking/L39_CombinationSum/Solution.cs b/csharp/11_BackTracking/L39_CombinationSum/Solution.cs
new file mode 100644
index 000000000..023b0f16b
--- /dev/null
+++ b/csharp/11_BackTracking/L39_CombinationSum/Solution.cs
@@ -0,0 +1,32 @@
+namespace _11_BackTracking.L39_CombinationSum;
+
+public class Solution
+{
+ public List> CombinationSum(int[] nums, int target)
+ {
+ var result = new List>();
+
+ depthFirstSearch(0, new List(), 0);
+
+ return result;
+
+ void depthFirstSearch(int index, List current, int total)
+ {
+ if (total == target)
+ {
+ // the .ToList() is used to copy current into a new one here,
+ // otherwise it keeps getting updated
+ result.Add(current.ToList());
+ return;
+ }
+
+ if (index >= nums.Length || total > target)
+ return;
+
+ current.Add(nums[index]);
+ depthFirstSearch(index, current, total + nums[index]);
+ current.Remove(current.Last());
+ depthFirstSearch(index + 1, current, total);
+ }
+ }
+}
\ No newline at end of file
diff --git a/csharp/11_BackTracking/L39_CombinationSum/readme.md b/csharp/11_BackTracking/L39_CombinationSum/readme.md
new file mode 100644
index 000000000..8121467a3
--- /dev/null
+++ b/csharp/11_BackTracking/L39_CombinationSum/readme.md
@@ -0,0 +1,42 @@
+# Combination Sum
+
+You are given an array of distinct integers nums and a target integer target.
+Your task is to return a list of all unique combinations of nums where the chosen numbers sum to target.
+The same number may be chosen from nums an unlimited number of times.
+Two combinations are the same if the frequency of each of the chosen numbers is the same, otherwise they are different.
+You may return the combinations in any order and the order of the numbers in each combination can be in any order.
+
+## Example 1
+
+Input:
+nums = [2,5,6,9]
+target = 9
+
+Output: [[2,2,5],[9]]
+
+Explanation:
+2 + 2 + 5 = 9. We use 2 twice, and 5 once.
+9 = 9. We use 9 once.
+
+## Example 2
+
+Input:
+nums = [3,4,5]
+target = 16
+
+Output: [[3,3,3,3,4],[3,3,5,5],[4,4,4,4],[3,4,4,5]]
+
+## Example 3
+
+Input:
+nums = [3]
+target = 5
+
+Output: []
+
+Constraints:
+
+- All elements of nums are distinct.
+- 1 <= nums.length <= 20
+- 2 <= nums[i] <= 30
+- 2 <= target <= 30
diff --git a/csharp/11_BackTracking/L79_WordSearch/Solution.cs b/csharp/11_BackTracking/L79_WordSearch/Solution.cs
new file mode 100644
index 000000000..0df6eb18a
--- /dev/null
+++ b/csharp/11_BackTracking/L79_WordSearch/Solution.cs
@@ -0,0 +1,50 @@
+using System.Data;
+
+namespace _11_BackTracking.WordSearch;
+
+public class Solution
+{
+ public int Iterations = 0;
+
+ // time complexity:
+ // O( r * c * 4^len(word) )
+ public bool Exist(char[][] board, string word)
+ {
+ var nrRows = board.Length;
+ var nrCols = board[0].Length;
+ var path = new HashSet<(int, int)>();
+
+ bool dfs(int r, int c, int wordIndex)
+ {
+ if (wordIndex == word.Length) return true;
+ if (r < 0 || c < 0 || r >= nrRows || r >= nrCols // out of bounds
+ || word[wordIndex] != board[r][c] // char does not match
+ || path.Contains((r, c))) // cell already visited
+ {
+ Iterations += 1;
+ return false;
+ }
+
+ path.Add((r, c));
+ ++wordIndex;
+ var result = dfs(r + 1, c, wordIndex)
+ || dfs(r - 1, c, wordIndex)
+ || dfs(r, c + 1, wordIndex)
+ || dfs(r, c - 1, wordIndex);
+ path.Remove((r, c));
+
+ return result;
+ }
+
+ for (int row = 0; row < nrRows; row++)
+ {
+ for (int col = 0; col < nrCols; col++)
+ {
+ if (dfs(row, col, 0))
+ return true;
+ }
+ }
+
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/csharp/11_BackTracking/L79_WordSearch/img.png b/csharp/11_BackTracking/L79_WordSearch/img.png
new file mode 100644
index 000000000..bf2647360
Binary files /dev/null and b/csharp/11_BackTracking/L79_WordSearch/img.png differ
diff --git a/csharp/11_BackTracking/L79_WordSearch/readme.md b/csharp/11_BackTracking/L79_WordSearch/readme.md
new file mode 100644
index 000000000..b21de8a21
--- /dev/null
+++ b/csharp/11_BackTracking/L79_WordSearch/readme.md
@@ -0,0 +1,37 @@
+# Word Search
+
+Given a 2-D grid of characters board and a string word, return true if the word is present in the grid, otherwise return false.
+
+For the word to be present it must be possible to form it with a path in the board with horizontally or vertically neighboring cells. The same cell may not be used more than once in a word.
+
+## Example 1
+
+
+
+Input:
+board = [
+["A","B","C","D"],
+["S","A","A","T"],
+["A","C","A","E"]
+],
+word = "CAT"
+
+Output: true
+
+## Example 2
+
+Input:
+board = [
+["A","B","C","D"],
+["S","A","A","T"],
+["A","C","A","E"]
+],
+word = "BAT"
+
+Output: false
+
+## Constraints:
+
+- 1 <= board.length, board[i].length <= 5
+- 1 <= word.length <= 10
+- board and word consists of only lowercase and uppercase English letters.
diff --git a/csharp/11_BackTracking/Permutations/Solution.cs b/csharp/11_BackTracking/Permutations/Solution.cs
new file mode 100644
index 000000000..53b05e960
--- /dev/null
+++ b/csharp/11_BackTracking/Permutations/Solution.cs
@@ -0,0 +1,30 @@
+namespace _11_BackTracking.Permutations;
+
+public class Solution
+{
+ /// Time commplexity:
+ /// O(n! * n^2)
+ /// n! for every time you call permute
+ /// n^2 because of the nested for into the foreach
+ public List> Permute(int[] nums)
+ {
+ var result = new List>();
+ if (nums.Length == 0)
+ return new List> { new() };
+
+ var permutations = Permute(nums[1..]);
+
+
+ foreach (var permutation in permutations)
+ {
+ for (int insertIndex = 0; insertIndex <= permutation.Count; insertIndex++)
+ {
+ var currentPermutation = permutation.ToList();
+ currentPermutation.Insert(insertIndex, nums[0]);
+ result.Add(currentPermutation);
+ }
+ }
+
+ return result;
+ }
+}
\ No newline at end of file
diff --git a/csharp/11_BackTracking/Permutations/readme.md b/csharp/11_BackTracking/Permutations/readme.md
new file mode 100644
index 000000000..9a238aa89
--- /dev/null
+++ b/csharp/11_BackTracking/Permutations/readme.md
@@ -0,0 +1,20 @@
+# Permutations
+
+Given an array nums of unique integers, return all the possible permutations. You may return the answer in any order.
+
+## Example 1
+
+Input: nums = [1,2,3]
+
+Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
+
+## Example 2
+
+Input: nums = [7]
+
+Output: [[7]]
+
+## Constraints
+
+- 1 <= nums.length <= 6
+- -10 <= nums[i] <= 10
diff --git a/csharp/13-1DDynamicProgramming/main/13_1DDynamicProgramming.csproj b/csharp/13-1DDynamicProgramming/main/13_1DDynamicProgramming.csproj
new file mode 100644
index 000000000..31849decd
--- /dev/null
+++ b/csharp/13-1DDynamicProgramming/main/13_1DDynamicProgramming.csproj
@@ -0,0 +1,10 @@
+
+
+
+ net8.0
+ enable
+ enable
+ false
+
+
+
diff --git a/csharp/13-1DDynamicProgramming/main/N1-L70-ClimbingStairs/Solution.cs b/csharp/13-1DDynamicProgramming/main/N1-L70-ClimbingStairs/Solution.cs
new file mode 100644
index 000000000..295bc64e2
--- /dev/null
+++ b/csharp/13-1DDynamicProgramming/main/N1-L70-ClimbingStairs/Solution.cs
@@ -0,0 +1,24 @@
+namespace OneDimDynamicProgramming.Main.ClimbingStairs
+{
+ //FIXME
+ // does not work with 3
+ public class Solution
+ {
+ // tc : O(n) <== looping over n
+ // sc : O(1) <== only two variables needed, regardless of n
+ public int ClimbStairs(int n)
+ {
+ int pt1 = 1;
+ int pt2 = 1;
+
+ for (int i = 1; i < n; i++)
+ {
+ int temp = pt1;
+ pt1 = pt1 + pt2;
+ pt2 = temp;
+ }
+
+ return pt1;
+ }
+ }
+}
\ No newline at end of file
diff --git a/csharp/13-1DDynamicProgramming/main/N1-L70-ClimbingStairs/readme.md b/csharp/13-1DDynamicProgramming/main/N1-L70-ClimbingStairs/readme.md
new file mode 100644
index 000000000..f40ef76de
--- /dev/null
+++ b/csharp/13-1DDynamicProgramming/main/N1-L70-ClimbingStairs/readme.md
@@ -0,0 +1,24 @@
+# L70. Climbing Stairs
+Easy
+
+You are climbing a staircase. It takes n steps to reach the top.
+
+Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
+
+
+## Example 1:
+
+Input: n = 2
+Output: 2
+Explanation: There are two ways to climb to the top.
+1. 1 step + 1 step
+2. 2 steps
+
+## Example 2:
+
+Input: n = 3
+Output: 3
+Explanation: There are three ways to climb to the top.
+1. 1 step + 1 step + 1 step
+2. 1 step + 2 steps
+3. 2 steps + 1 step
diff --git a/csharp/13-1DDynamicProgramming/main/N2-L746-MinCostClimbingStairs/Solution.cs b/csharp/13-1DDynamicProgramming/main/N2-L746-MinCostClimbingStairs/Solution.cs
new file mode 100644
index 000000000..63f154273
--- /dev/null
+++ b/csharp/13-1DDynamicProgramming/main/N2-L746-MinCostClimbingStairs/Solution.cs
@@ -0,0 +1,23 @@
+namespace OneDimDynamicProgramming.Main.MinCostClimbingStairs
+{
+ // tc : O(n)
+ // sc : O(1)
+ public class Solution
+ {
+ public int MinCostClimbingStairs(int[] cost)
+ {
+ cost.Append(0);
+
+ for (int i = cost.Length - 3; i >= 0; i--)
+ {
+ // original understandable code :
+ // cost[i] = Math.Min(cost[i]+cost[i+1],cost[i] + cost[i + 2]);
+ // optimization :
+ cost[i] += Math.Min(cost[i + 1], cost[i + 2]);
+ }
+
+ // this is safe because of the constraint cost.lenght >= 2
+ return Math.Min(cost[0],cost[1]);
+ }
+ }
+}
\ No newline at end of file
diff --git a/csharp/13-1DDynamicProgramming/main/N2-L746-MinCostClimbingStairs/readme.md b/csharp/13-1DDynamicProgramming/main/N2-L746-MinCostClimbingStairs/readme.md
new file mode 100644
index 000000000..96e52ffef
--- /dev/null
+++ b/csharp/13-1DDynamicProgramming/main/N2-L746-MinCostClimbingStairs/readme.md
@@ -0,0 +1,37 @@
+# L746. Min Cost Climbing Stairs
+Easy
+
+You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps.
+
+You can either start from the step with index 0, or the step with index 1.
+
+Return the minimum cost to reach the top of the floor.
+
+## Example 1
+
+Input: cost = [10,15,20]
+Output: 15
+Explanation: You will start at index 1.
+- Pay 15 and climb two steps to reach the top.
+The total cost is 15.
+
+## Example 2
+
+Input: cost = [1,100,1,1,1,100,1,1,100,1]
+Output: 6
+Explanation: You will start at index 0.
+- Pay 1 and climb two steps to reach index 2.
+- Pay 1 and climb two steps to reach index 4.
+- Pay 1 and climb two steps to reach index 6.
+- Pay 1 and climb one step to reach index 7.
+- Pay 1 and climb two steps to reach index 9.
+- Pay 1 and climb one step to reach the top.
+The total cost is 6.
+
+
+
+Constraints:
+
+ 2 <= cost.length <= 1000
+ 0 <= cost[i] <= 999
+
diff --git a/csharp/13-1DDynamicProgramming/main/N3-L198-HouseRobber/Solution.cs b/csharp/13-1DDynamicProgramming/main/N3-L198-HouseRobber/Solution.cs
new file mode 100644
index 000000000..dcd693947
--- /dev/null
+++ b/csharp/13-1DDynamicProgramming/main/N3-L198-HouseRobber/Solution.cs
@@ -0,0 +1,22 @@
+namespace OneDimDynamicProgramming.Main.HouseRobber
+{
+ // tc : O(n), where n = nums.Length
+ // sc : O(1) <-- need only two vars : s1, s2
+ public class Solution
+ {
+ public int Rob(int[] nums)
+ {
+ int s2 = 0;
+ int s1 = 0;
+
+ foreach (var x in nums)
+ {
+ int s3 = Math.Max(s2, x + s1);
+ s1 = s2;
+ s2 = s3;
+ }
+
+ return s2;
+ }
+ }
+}
diff --git a/csharp/13-1DDynamicProgramming/main/N3-L198-HouseRobber/readme.md b/csharp/13-1DDynamicProgramming/main/N3-L198-HouseRobber/readme.md
new file mode 100644
index 000000000..5feea7f22
--- /dev/null
+++ b/csharp/13-1DDynamicProgramming/main/N3-L198-HouseRobber/readme.md
@@ -0,0 +1,36 @@
+# L66. House Robber
+
+You are a professional robber planning to rob houses along a street.
+Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night.
+
+Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.
+
+
+## Example 1:
+
+Input: nums = [1,2,3,1]
+Output: 4
+Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).
+Total amount you can rob = 1 + 3 = 4.
+
+## Example 2:
+
+Input: nums = [2,7,9,3,1]
+Output: 12
+Explanation: Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5 (money = 1).
+Total amount you can rob = 2 + 9 + 1 = 12.
+
+
+## Constraints:
+
+ 1 <= nums.length <= 100
+ 0 <= nums[i] <= 400
+
+## My notes
+
+The recursion formula is
+
+$$
+s_i = \max(s_{i-1},n_i+s_{i-2})
+$$
+
diff --git a/csharp/13-1DDynamicProgramming/main/N4-L213-HouseRobber2/Solution.cs b/csharp/13-1DDynamicProgramming/main/N4-L213-HouseRobber2/Solution.cs
new file mode 100644
index 000000000..17097a079
--- /dev/null
+++ b/csharp/13-1DDynamicProgramming/main/N4-L213-HouseRobber2/Solution.cs
@@ -0,0 +1,31 @@
+using System.Linq;
+
+namespace OneDimDynamicProgramming.Main.HouseRobber2
+{
+ public class Solution
+ {
+ public int Rob(int[] nums)
+ {
+ if (nums.Length == 1)
+ return nums[0];
+
+ return Math.Max(rob1(nums.Skip(1).ToArray()), rob1(nums.Take(nums.Length - 1).ToArray()));
+ }
+
+ private int rob1(int[] nums)
+ {
+ int s2 = 0;
+ int s1 = 0;
+
+ foreach (var x in nums)
+ {
+ int s3 = Math.Max(s2, x + s1);
+ s1 = s2;
+ s2 = s3;
+ }
+
+ return s2;
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/csharp/13-1DDynamicProgramming/testCases/13_1DDynamicProgramming_Tests.csproj b/csharp/13-1DDynamicProgramming/testCases/13_1DDynamicProgramming_Tests.csproj
new file mode 100644
index 000000000..339ca47d9
--- /dev/null
+++ b/csharp/13-1DDynamicProgramming/testCases/13_1DDynamicProgramming_Tests.csproj
@@ -0,0 +1,19 @@
+
+
+
+ net8.0
+ enable
+ false
+ false
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/csharp/13-1DDynamicProgramming/testCases/N1-L70-ClimbingStairs.cs b/csharp/13-1DDynamicProgramming/testCases/N1-L70-ClimbingStairs.cs
new file mode 100644
index 000000000..893c97502
--- /dev/null
+++ b/csharp/13-1DDynamicProgramming/testCases/N1-L70-ClimbingStairs.cs
@@ -0,0 +1,27 @@
+using FluentAssertions;
+using NUnit.Framework;
+using OneDimDynamicProgramming.Main.ClimbingStairs;
+
+namespace testCases;
+
+public class ClimbingStairs_Test
+{
+
+ [Test]
+ public void Test_Example_1()
+ {
+ Solution solution = new();
+ int testResult = solution.ClimbStairs(2);
+
+ testResult.Should().Be(2);
+ }
+
+ [Test]
+ public void Test_Example_2()
+ {
+ Solution solution = new();
+ int testResult = solution.ClimbStairs(3);
+
+ testResult.Should().Be(3);
+ }
+}
\ No newline at end of file
diff --git a/csharp/13-1DDynamicProgramming/testCases/N2-L746-MinCostClimbingStairs.cs b/csharp/13-1DDynamicProgramming/testCases/N2-L746-MinCostClimbingStairs.cs
new file mode 100644
index 000000000..502d5be84
--- /dev/null
+++ b/csharp/13-1DDynamicProgramming/testCases/N2-L746-MinCostClimbingStairs.cs
@@ -0,0 +1,31 @@
+using FluentAssertions;
+using NUnit.Framework;
+using OneDimDynamicProgramming.Main.MinCostClimbingStairs;
+
+namespace testCases;
+
+public class MinCostClimbingStairs_Test
+{
+
+ [Test]
+ public void Test_Example_1()
+ {
+ int[] input = {10,15,20};
+
+ Solution solution = new();
+ int testResult = solution.MinCostClimbingStairs(input);
+
+ testResult.Should().Be(15);
+ }
+
+ [Test]
+ public void Test_Example_2()
+ {
+ int[] input = {1, 100, 1, 1, 1, 100, 1, 1, 100, 1 };
+
+ Solution solution = new();
+ int testResult = solution.MinCostClimbingStairs(input);
+
+ testResult.Should().Be(6);
+ }
+}
\ No newline at end of file
diff --git a/csharp/13-1DDynamicProgramming/testCases/N3-L198-HouseRobber_Test.cs b/csharp/13-1DDynamicProgramming/testCases/N3-L198-HouseRobber_Test.cs
new file mode 100644
index 000000000..fba857bcf
--- /dev/null
+++ b/csharp/13-1DDynamicProgramming/testCases/N3-L198-HouseRobber_Test.cs
@@ -0,0 +1,30 @@
+using FluentAssertions;
+using NUnit.Framework;
+using OneDimDynamicProgramming.Main.HouseRobber;
+
+namespace testCases;
+
+public class HouseRobber_Test
+{
+ [Test]
+ public void Test_Example_1()
+ {
+ int[] input = {1,2,3,1};
+
+ OneDimDynamicProgramming.Main.HouseRobber.Solution solution = new();
+ int test_result = solution.Rob(input);
+
+ test_result.Should().Be(4);
+ }
+
+ [Test]
+ public void Test_Example_2()
+ {
+ int[] input = { 2, 7, 9, 3, 1 };
+
+ OneDimDynamicProgramming.Main.HouseRobber.Solution solution = new();
+ int test_result = solution.Rob(input);
+
+ test_result.Should().Be(12);
+ }
+}
\ No newline at end of file
diff --git a/csharp/14-2dDynamicProgramming/main/14_2dDynamicProgramming.csproj b/csharp/14-2dDynamicProgramming/main/14_2dDynamicProgramming.csproj
new file mode 100644
index 000000000..5ee08fb57
--- /dev/null
+++ b/csharp/14-2dDynamicProgramming/main/14_2dDynamicProgramming.csproj
@@ -0,0 +1,10 @@
+
+
+
+ net8.0
+ enable
+ false
+ enable
+
+
+
diff --git a/csharp/14-2dDynamicProgramming/main/L53-MaximumSubArray/Solution.cs b/csharp/14-2dDynamicProgramming/main/L53-MaximumSubArray/Solution.cs
new file mode 100644
index 000000000..50fbc0d28
--- /dev/null
+++ b/csharp/14-2dDynamicProgramming/main/L53-MaximumSubArray/Solution.cs
@@ -0,0 +1,26 @@
+namespace TwoDimDynamicProgrammin.Main.MaximumSubarray
+{
+ // TC : O(n) <== only one loop over the array
+ // SC : O(1) <== using only two variables
+ public class Solution
+ {
+ public int MaxSubArray(int[] nums)
+ {
+ if (nums.Length == 1)
+ return nums[0];
+
+ int currentSum = 0;
+ int MaximumSubarray = Int32.MinValue;
+
+ foreach (int number in nums)
+ {
+ if (currentSum < 0)
+ currentSum = 0;
+ currentSum += number;
+ MaximumSubarray = Math.Max(MaximumSubarray,currentSum);
+ }
+
+ return MaximumSubarray;
+ }
+ }
+}
\ No newline at end of file
diff --git a/csharp/14-2dDynamicProgramming/main/L53-MaximumSubArray/readme.md b/csharp/14-2dDynamicProgramming/main/L53-MaximumSubArray/readme.md
new file mode 100644
index 000000000..281df574e
--- /dev/null
+++ b/csharp/14-2dDynamicProgramming/main/L53-MaximumSubArray/readme.md
@@ -0,0 +1,31 @@
+# L53. Maximum Subarray
+Easy
+
+Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.
+
+A subarray is a contiguous part of an array.
+
+## Example 1
+
+Input: nums = [-2,1,-3,4,-1,2,1,-5,4]
+Output: 6
+Explanation: [4,-1,2,1] has the largest sum = 6.
+
+## Example 2
+
+Input: nums = [1]
+Output: 1
+
+## Example 3
+
+Input: nums = [5,4,-1,7,8]
+Output: 23
+
+## Constraints:
+
+1 <= nums.length <= 105
+-104 <= nums[i] <= 104
+
+## Extra
+
+Follow up: If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.
diff --git a/csharp/14-2dDynamicProgramming/testCases/14_2dDynamicProgramming_Tests.csproj b/csharp/14-2dDynamicProgramming/testCases/14_2dDynamicProgramming_Tests.csproj
new file mode 100644
index 000000000..3d2828b49
--- /dev/null
+++ b/csharp/14-2dDynamicProgramming/testCases/14_2dDynamicProgramming_Tests.csproj
@@ -0,0 +1,19 @@
+
+
+
+ net8.0
+ enable
+ false
+ false
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/csharp/14-2dDynamicProgramming/testCases/L53-MaximumSubarray_Test.cs b/csharp/14-2dDynamicProgramming/testCases/L53-MaximumSubarray_Test.cs
new file mode 100644
index 000000000..0cf605c98
--- /dev/null
+++ b/csharp/14-2dDynamicProgramming/testCases/L53-MaximumSubarray_Test.cs
@@ -0,0 +1,52 @@
+using FluentAssertions;
+using NUnit.Framework;
+using TwoDimDynamicProgrammin.Main.MaximumSubarray;
+
+namespace testCases;
+
+public class MaximumSubarray_Test
+{
+ [Test]
+ public void Test_Example_1()
+ {
+ int[] input = { -2, 1, -3, 4, -1, 2, 1, -5, 4 };
+
+ Solution solution = new();
+ int testResult = solution.MaxSubArray(input);
+
+ testResult.Should().Be(6);
+ }
+
+ [Test]
+ public void Test_Example_2()
+ {
+ int[] input = {1};
+
+ Solution solution = new();
+ int testResult = solution.MaxSubArray(input);
+
+ testResult.Should().Be(1);
+ }
+
+ [Test]
+ public void Test_Example_3()
+ {
+ int[] input = {5, 4, -1, 7, 8 };
+
+ Solution solution = new();
+ int testResult = solution.MaxSubArray(input);
+
+ testResult.Should().Be(23);
+ }
+
+ [Test]
+ public void Test_Example_4()
+ {
+ int[] input = {-1};
+
+ Solution solution = new();
+ int testResult = solution.MaxSubArray(input);
+
+ testResult.Should().Be(-1);
+ }
+}
\ No newline at end of file
diff --git a/csharp/16-Intervals/main/16_Intervals.csproj b/csharp/16-Intervals/main/16_Intervals.csproj
new file mode 100644
index 000000000..30402ac0e
--- /dev/null
+++ b/csharp/16-Intervals/main/16_Intervals.csproj
@@ -0,0 +1,9 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
diff --git a/csharp/16-Intervals/main/L252-MeetingRoom/Solution.cs b/csharp/16-Intervals/main/L252-MeetingRoom/Solution.cs
new file mode 100644
index 000000000..6568b8a8c
--- /dev/null
+++ b/csharp/16-Intervals/main/L252-MeetingRoom/Solution.cs
@@ -0,0 +1,88 @@
+namespace _16_Intervals.L252_MeetingRoom
+{
+
+ // Definition of Interval:
+ public class Interval
+ {
+ public int start, end;
+ public Interval(int start, int end)
+ {
+ this.start = start;
+ this.end = end;
+ }
+ }
+
+ public class Solution
+ {
+ /**
+ * @param intervals: an array of meeting time intervals
+ * @return: if a person could attend all meetings
+ **/
+ public bool CanAttendMeetings(List intervals)
+ {
+ // Write your code here
+ intervals.Sort(SortByStartTimeHelper.CompareStartTime);
+
+ for (int i = 1; i < intervals.Count; i++)
+ {
+ Interval i1 = intervals[i-1];
+ Interval i2 = intervals[i];
+
+ if (i1.end > i2.start)
+ return false;
+ }
+ return true;
+ }
+
+ }
+
+ public class SortByStartTimeHelper
+ {
+ public static int CompareStartTime(Interval a, Interval b)
+ {
+ if (a.start > b.start)
+ return 1;
+ if (a.start < b.start)
+ return -1;
+
+ return 0;
+ }
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}
\ No newline at end of file
diff --git a/csharp/16-Intervals/main/L252-MeetingRoom/readme.md b/csharp/16-Intervals/main/L252-MeetingRoom/readme.md
new file mode 100644
index 000000000..9e9061be9
--- /dev/null
+++ b/csharp/16-Intervals/main/L252-MeetingRoom/readme.md
@@ -0,0 +1,28 @@
+# L252 - Meeting Rooms
+
+
+Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), determine if a person could attend all meetings.
+
+## Example1
+
+Input: intervals = [(0,30),(5,10),(15,20)]
+
+Output: false
+
+Explanation:
+
+(0,30), (5,10) and (0,30),(15,20) will conflict
+
+## Example2
+
+Input: intervals = [(5,8),(9,15)]
+
+Output: true
+
+Explanation:
+
+Two times will not conflict
+
+## Constraints
+- 0 <= intervals.length <= 500
+- 0 <= intervals[i].start < intervals[i].end <= 1,000,000
diff --git a/csharp/16_Intervals_Tests/16_Intervals_Tests.csproj b/csharp/16_Intervals_Tests/16_Intervals_Tests.csproj
new file mode 100644
index 000000000..2b42d70d9
--- /dev/null
+++ b/csharp/16_Intervals_Tests/16_Intervals_Tests.csproj
@@ -0,0 +1,20 @@
+
+
+
+ net8.0
+ _16_Intervals_Tests
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/csharp/16_Intervals_Tests/L252_IntervalsTests.cs b/csharp/16_Intervals_Tests/L252_IntervalsTests.cs
new file mode 100644
index 000000000..a200c9b1a
--- /dev/null
+++ b/csharp/16_Intervals_Tests/L252_IntervalsTests.cs
@@ -0,0 +1,40 @@
+using _16_Intervals.L252_MeetingRoom;
+using FluentAssertions;
+using NUnit.Framework;
+
+namespace _16_Intervals_Tests;
+
+public class L252_IntervalsTests
+{
+ [Test]
+ public void Example1_Test()
+ {
+ var intervals = new List()
+ {
+ new(0, 30),
+ new(5, 10),
+ new(15, 20)
+ };
+
+ var solution = new Solution();
+ var result = solution.CanAttendMeetings(intervals);
+
+ result.Should().Be(false);
+ }
+
+ [Test]
+ public void Example2_Test()
+ {
+ var intervals = new List()
+ {
+ new(5, 8),
+ new(9, 15)
+
+ };
+ var solution = new Solution();
+ var result = solution.CanAttendMeetings(intervals);
+
+ result.Should().Be(true);
+ }
+
+}
diff --git a/csharp/17-MathAndGeometry/main/17_MathAndGeometry.csproj b/csharp/17-MathAndGeometry/main/17_MathAndGeometry.csproj
new file mode 100644
index 000000000..d499990ce
--- /dev/null
+++ b/csharp/17-MathAndGeometry/main/17_MathAndGeometry.csproj
@@ -0,0 +1,10 @@
+
+
+
+ net8.0
+ enable
+ enable
+ false
+
+
+
\ No newline at end of file
diff --git a/csharp/17-MathAndGeometry/main/L202-HappyNumber/Solution.cs b/csharp/17-MathAndGeometry/main/L202-HappyNumber/Solution.cs
new file mode 100644
index 000000000..04a43107a
--- /dev/null
+++ b/csharp/17-MathAndGeometry/main/L202-HappyNumber/Solution.cs
@@ -0,0 +1,39 @@
+namespace MathAndGeometry.Main.HappyNumber
+{
+ // based on https://www.youtube.com/watch?v=ljz85bxOYJ0
+ // time complexity : Hashsets have lookup time O(1) (https://stackoverflow.com/questions/9812020/what-is-the-lookup-time-complexity-of-hashsettiequalitycomparert), but you are still looping over n, so I'd say O(n)
+ // space complexity : O(n) <== using Hashset
+ public class Solution
+ {
+
+ public bool IsHappy(int n)
+ {
+ HashSet visited = new();
+
+ while (!visited.Contains(n))
+ {
+ visited.Add(n);
+ n = squareAndAddDigits(n);
+
+ if (n == 1)
+ return true;
+ }
+
+ return false;
+ }
+
+ private int squareAndAddDigits(int n)
+ {
+ int retval = 0;
+
+ while (n != 0)
+ {
+ int digit = n % 10;
+ retval += (int)Math.Pow(digit, 2);
+ n = n / 10;
+ }
+
+ return retval;
+ }
+ }
+}
diff --git a/csharp/17-MathAndGeometry/main/L202-HappyNumber/readme.md b/csharp/17-MathAndGeometry/main/L202-HappyNumber/readme.md
new file mode 100644
index 000000000..e69de29bb
diff --git a/csharp/17-MathAndGeometry/main/L66-PlusOne/Solution.cs b/csharp/17-MathAndGeometry/main/L66-PlusOne/Solution.cs
new file mode 100644
index 000000000..e8b47977c
--- /dev/null
+++ b/csharp/17-MathAndGeometry/main/L66-PlusOne/Solution.cs
@@ -0,0 +1,32 @@
+namespace MathAndGeometry.Main.PlusOne;
+public class Solution
+{
+ // tc : O(n)
+ // sc : O(1)
+ public int[] PlusOne(int[] digits)
+ {
+ int last_index = digits.Length - 1;
+ digits[last_index]++;
+
+ int index = last_index;
+ while (digits[index] == 10 && index >= 0)
+ {
+ // set digit to zero
+ digits[index] = 0;
+ // move pointer to next digit
+ index--;
+ if (index == -1)
+ {
+ int[] longerArray = new int[digits.Length + 1];
+ longerArray[0] = 1;
+ Array.Copy(digits, 0, longerArray, 1, digits.Length);
+ return longerArray;
+ }
+ // add the carry
+ digits[index]++;
+ }
+
+
+ return digits;
+ }
+}
\ No newline at end of file
diff --git a/csharp/17-MathAndGeometry/main/L66-PlusOne/readme.md b/csharp/17-MathAndGeometry/main/L66-PlusOne/readme.md
new file mode 100644
index 000000000..54ee3eb35
--- /dev/null
+++ b/csharp/17-MathAndGeometry/main/L66-PlusOne/readme.md
@@ -0,0 +1,37 @@
+# L66. Plus One
+Easy
+
+You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's.
+
+Increment the large integer by one and return the resulting array of digits.
+
+## Example 1:
+
+Input: digits = [1,2,3]
+Output: [1,2,4]
+Explanation: The array represents the integer 123.
+Incrementing by one gives 123 + 1 = 124.
+Thus, the result should be [1,2,4].
+
+## Example 2:
+
+Input: digits = [4,3,2,1]
+Output: [4,3,2,2]
+Explanation: The array represents the integer 4321.
+Incrementing by one gives 4321 + 1 = 4322.
+Thus, the result should be [4,3,2,2].
+
+## Example 3:
+
+Input: digits = [9]
+Output: [1,0]
+Explanation: The array represents the integer 9.
+Incrementing by one gives 9 + 1 = 10.
+Thus, the result should be [1,0].
+
+## Constraints:
+
+1 <= digits.length <= 100
+0 <= digits[i] <= 9
+digits does not contain any leading 0's.
+
diff --git a/csharp/17-MathAndGeometry/testCases/17_MathAndGeometry_Tests.csproj b/csharp/17-MathAndGeometry/testCases/17_MathAndGeometry_Tests.csproj
new file mode 100644
index 000000000..296ef79cc
--- /dev/null
+++ b/csharp/17-MathAndGeometry/testCases/17_MathAndGeometry_Tests.csproj
@@ -0,0 +1,19 @@
+
+
+
+ net8.0
+ enable
+ false
+ false
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/csharp/17-MathAndGeometry/testCases/N1-L202-HappyNumber.cs b/csharp/17-MathAndGeometry/testCases/N1-L202-HappyNumber.cs
new file mode 100644
index 000000000..b409817fd
--- /dev/null
+++ b/csharp/17-MathAndGeometry/testCases/N1-L202-HappyNumber.cs
@@ -0,0 +1,33 @@
+using System;
+using System.ComponentModel.DataAnnotations;
+using FluentAssertions;
+using MathAndGeometry.Main.HappyNumber;
+using NUnit.Framework;
+
+namespace testCases;
+
+public class HappyNumber_Test
+{
+
+ [Test]
+ public void Test_Example_1()
+ {
+ int inputTest1 = 19;
+
+ Solution solution = new();
+ bool testResult = solution.IsHappy(inputTest1);
+
+ testResult.Should().Be(true);
+ }
+
+ [Test]
+ public void Test_Example_2()
+ {
+ int inputTest1 = 2;
+
+ Solution solution = new();
+ bool testResult = solution.IsHappy(inputTest1);
+
+ testResult.Should().Be(false);
+ }
+}
\ No newline at end of file
diff --git a/csharp/17-MathAndGeometry/testCases/N2-L66-PlusOne_Test.cs b/csharp/17-MathAndGeometry/testCases/N2-L66-PlusOne_Test.cs
new file mode 100644
index 000000000..a5f04689e
--- /dev/null
+++ b/csharp/17-MathAndGeometry/testCases/N2-L66-PlusOne_Test.cs
@@ -0,0 +1,46 @@
+using FluentAssertions;
+using MathAndGeometry.Main.PlusOne;
+using NUnit.Framework;
+
+namespace testCases;
+
+public class PlusOne_Test
+{
+
+ [Test]
+ public void Test_Example_1()
+ {
+ int[] inputTest1 = {1,2,3};
+ int[] expectedOutput1 = {1,2,4};
+
+ Solution solution = new();
+ int[] testResult = solution.PlusOne(inputTest1);
+
+ testResult.Should().Equal(expectedOutput1);
+ }
+
+ [Test]
+ public void Test_Example_2()
+ {
+ int[] inputTest = { 1, 9, 9 };
+ int[] expectedOutput = { 2, 0, 0 };
+
+ Solution solution = new();
+ int[] testResult = solution.PlusOne(inputTest);
+
+ testResult.Should().Equal(expectedOutput);
+ }
+
+ [Test]
+ public void Test_Example_3()
+ {
+ int[] inputTest = { 9, 9, 9 };
+ int[] expectedOutput = { 1, 0, 0, 0 };
+
+ Solution solution = new();
+ int[] testResult = solution.PlusOne(inputTest);
+
+ testResult.Should().Equal(expectedOutput);
+ }
+
+}
\ No newline at end of file
diff --git a/csharp/18_BitManipulation/18_BitManipulation.csproj b/csharp/18_BitManipulation/18_BitManipulation.csproj
new file mode 100644
index 000000000..98112cfd9
--- /dev/null
+++ b/csharp/18_BitManipulation/18_BitManipulation.csproj
@@ -0,0 +1,10 @@
+
+
+
+ net8.0
+ _18_BitManipulation
+ enable
+ enable
+
+
+
diff --git a/csharp/18_BitManipulation/L191-NumberOfOneBits/Solution.cs b/csharp/18_BitManipulation/L191-NumberOfOneBits/Solution.cs
new file mode 100644
index 000000000..b1ea08cb9
--- /dev/null
+++ b/csharp/18_BitManipulation/L191-NumberOfOneBits/Solution.cs
@@ -0,0 +1,29 @@
+namespace _18_BitManipulation.L191_NumberOfOneBits;
+
+public class Solution {
+
+ // time complexity: O(32) = O(1) : constant
+ public int HammingWeightByMod(uint n)
+ {
+ var numberOfOnes = 0;
+
+ for (int i = 0; i < 32; i++)
+ {
+ // select the order of magnitued in base 2
+ // by bit-shifting 1
+ var shiftedI = 1 << i;
+
+ // bitwise logical AND
+ // 0 * 0 = 0
+ // 0 * 1 = 0
+ // 1 * 1 = 1
+ var bitWiseMultip = shiftedI & n;
+
+ // increase number of 1 bits
+ if (bitWiseMultip != 0)
+ numberOfOnes++;
+ }
+
+ return numberOfOnes;
+ }
+}
diff --git a/csharp/18_BitManipulation/L191-NumberOfOneBits/readme.md b/csharp/18_BitManipulation/L191-NumberOfOneBits/readme.md
new file mode 100644
index 000000000..4e53a86e9
--- /dev/null
+++ b/csharp/18_BitManipulation/L191-NumberOfOneBits/readme.md
@@ -0,0 +1,15 @@
+# Number of One Bits
+
+You are given an unsigned integer n. Return the number of 1 bits in its binary representation.
+
+You may assume n is a non-negative integer which fits within 32-bits.
+
+## Example 1
+
+Input: n = 00000000000000000000000000010111
+Output: 4
+
+## Example 2:
+
+Input: n = 01111111111111111111111111111101
+Output: 30
diff --git a/csharp/18_BitManipulation/L338-CountingBits/Solution.cs b/csharp/18_BitManipulation/L338-CountingBits/Solution.cs
new file mode 100644
index 000000000..588a10e24
--- /dev/null
+++ b/csharp/18_BitManipulation/L338-CountingBits/Solution.cs
@@ -0,0 +1,25 @@
+namespace _18_BitManipulation.L338_CountingBits;
+
+// time complexity: O(n)
+// this is just a loop over the NumberOfOneBits Solution,
+// which here I wrote in a more compact form
+public class Solution {
+ public int[] CountBits(int n)
+ {
+ var result = new int[n+1];
+
+ for (int i = 0; i < n+1; i++)
+ {
+ var numberOfOnes = 0;
+
+ for (int j = 0; j < 32; j++)
+ {
+ numberOfOnes += ((1 << j) & i) == 0 ? 0 : 1;
+ }
+
+ result[i] = numberOfOnes;
+ }
+
+ return result;
+ }
+}
diff --git a/csharp/18_BitManipulation/L338-CountingBits/readme.md b/csharp/18_BitManipulation/L338-CountingBits/readme.md
new file mode 100644
index 000000000..168cacc8c
--- /dev/null
+++ b/csharp/18_BitManipulation/L338-CountingBits/readme.md
@@ -0,0 +1,22 @@
+# Counting Bits
+
+Given an integer n, count the number of 1's in the binary representation of every number in the range [0, n].
+
+Return an array output where output[i] is the number of 1's in the binary representation of i.
+
+## Example 1
+
+Input: n = 4
+Output: [0,1,1,2,1]
+
+Explanation:
+0 --> 0
+1 --> 1
+2 --> 10
+3 --> 11
+4 --> 100
+
+Constraints:
+
+- 0 <= n <= 1000
+
diff --git a/csharp/18_BitManipulation_Tests/18_BitManipulation_Tests.csproj b/csharp/18_BitManipulation_Tests/18_BitManipulation_Tests.csproj
new file mode 100644
index 000000000..63b457a06
--- /dev/null
+++ b/csharp/18_BitManipulation_Tests/18_BitManipulation_Tests.csproj
@@ -0,0 +1,22 @@
+
+
+
+ net8.0
+ _18_BitManipulation_Tests
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/csharp/18_BitManipulation_Tests/L191_NumberOfOneBits_Tests.cs b/csharp/18_BitManipulation_Tests/L191_NumberOfOneBits_Tests.cs
new file mode 100644
index 000000000..79b12ec15
--- /dev/null
+++ b/csharp/18_BitManipulation_Tests/L191_NumberOfOneBits_Tests.cs
@@ -0,0 +1,31 @@
+using System.ComponentModel.Design;
+using _18_BitManipulation.L191_NumberOfOneBits;
+using FluentAssertions;
+using NUnit.Framework;
+
+namespace _18_BitManipulation_Tests;
+
+public class L191_NumberOfOneBits_Tests
+{
+ [Test]
+ public void Example1_Test()
+ {
+ uint input = 0b10111;
+
+ var solution = new Solution();
+ var result = solution.HammingWeightByMod(input);
+
+ result.Should().Be(4);
+ }
+
+ [Test]
+ public void Example2_Test()
+ {
+ uint input = 0b01111111111111111111111111111101;
+
+ var solution = new Solution();
+ var result = solution.HammingWeightByMod(input);
+
+ result.Should().Be(30);
+ }
+}
\ No newline at end of file
diff --git a/csharp/18_BitManipulation_Tests/L338_CountingBits_Tests.cs b/csharp/18_BitManipulation_Tests/L338_CountingBits_Tests.cs
new file mode 100644
index 000000000..395d46e07
--- /dev/null
+++ b/csharp/18_BitManipulation_Tests/L338_CountingBits_Tests.cs
@@ -0,0 +1,23 @@
+using FluentAssertions;
+using NUnit.Framework;
+
+namespace _18_BitManipulation_Tests;
+
+public class L338_CountingBits_Tests
+{
+ [Test]
+ public void Example1_Tests()
+ {
+ var input = 4;
+
+ var solution = new _18_BitManipulation.L338_CountingBits.Solution();
+ var result = solution.CountBits(input);
+
+ result.Length.Should().Be(input + 1);
+ result[0].Should().Be(0);
+ result[1].Should().Be(1);
+ result[2].Should().Be(1);
+ result[3].Should().Be(2);
+ result[4].Should().Be(1);
+ }
+}
\ No newline at end of file
diff --git a/csharp/2-TwoPointers/main/2_TwoPointers.csproj b/csharp/2-TwoPointers/main/2_TwoPointers.csproj
new file mode 100644
index 000000000..d2b0a5fab
--- /dev/null
+++ b/csharp/2-TwoPointers/main/2_TwoPointers.csproj
@@ -0,0 +1,10 @@
+
+
+
+ net8.0
+ enable
+ enable
+ false
+
+
+
diff --git a/csharp/2-TwoPointers/main/N1-L125-ValidPalindrome/Solution.cs b/csharp/2-TwoPointers/main/N1-L125-ValidPalindrome/Solution.cs
new file mode 100644
index 000000000..4866e265b
--- /dev/null
+++ b/csharp/2-TwoPointers/main/N1-L125-ValidPalindrome/Solution.cs
@@ -0,0 +1,84 @@
+using System.Text.RegularExpressions;
+
+namespace TwoPointers.Main.ValidPalindrome
+{
+ public class Solution
+ {
+ // I am not sure of the complexity of my solution :-(
+ public bool IsPalindrome(string s)
+ {
+ //FIRST SUBMISSION
+ // List cleanInput = new();
+ // foreach (char item in s)
+ // {
+ // Regex regex = new Regex("[a-zA-Z0-9]");
+ // Match match = regex.Match(item.ToString());
+
+ // if (match.Success)
+ // cleanInput.Add(item.ToString().ToLower().ElementAt(0));
+ // }
+
+ // A bit slower
+ // int cleanInputLength = cleanInput.Count;
+ // for (int i = 0; i < cleanInputLength / 2; i++)
+ // {
+ // if (cleanInput[i] != cleanInput[cleanInputLength - 1 - i])
+ // return false;
+ // }
+
+ // FINAL submission
+ // I like this solution because :
+ // - it's faster than the previous one : 81 < 586
+ // - it uses built-in fcts to perform the checks :
+ // - if a char is alphanumeric
+ // - if the cleaned up string is a palindrome
+ // - it reduces the ammount of back and forth between char list or arrays and strings
+ string str = s.ToLower();
+ char[] cleaInputCharArr = str.Where(c => Char.IsLetterOrDigit(c)).ToArray();
+
+ string cleanInputString = new(cleaInputCharArr);
+ Array.Reverse(cleaInputCharArr);
+ string reversedString = new(cleaInputCharArr);
+ if (cleanInputString == reversedString)
+ return true;
+
+ return false;
+ }
+
+ // **BEST**
+ // This solution ( taken from LeetCode) is super fast (51 ms) and actually uses pointers
+ // It's the C# version of the one suggested by NeetCode
+ // time complexity : O(n)
+ // memory complexity : O(1)
+ public bool IsPalindromeInsane(string st)
+ {
+ var s = st.ToLower();
+
+ int left = 0;
+ int right = s.Length - 1;
+
+ while (left < right)
+ {
+ while (left < right && !Char.IsLetterOrDigit(s[left]))
+ {
+ left++;
+ }
+ while (left < right && !Char.IsLetterOrDigit(s[right]))
+ {
+ right--;
+ }
+
+ if (s[left] != s[right])
+ {
+ return false;
+ }
+ left++;
+ right--;
+ }
+
+ return true;
+ }
+ }
+
+
+}
\ No newline at end of file
diff --git a/csharp/2-TwoPointers/main/N1-L125-ValidPalindrome/readme.md b/csharp/2-TwoPointers/main/N1-L125-ValidPalindrome/readme.md
new file mode 100644
index 000000000..096ad8dee
--- /dev/null
+++ b/csharp/2-TwoPointers/main/N1-L125-ValidPalindrome/readme.md
@@ -0,0 +1,29 @@
+# N1-L125. Valid Palindrome
+
+A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.
+
+Given a string s, return true if it is a palindrome, or false otherwise.
+
+## Example 1:
+
+Input: s = "A man, a plan, a canal: Panama"
+Output: true
+Explanation: "amanaplanacanalpanama" is a palindrome.
+
+## Example 2:
+
+Input: s = "race a car"
+Output: false
+Explanation: "raceacar" is not a palindrome.
+
+## Example 3:
+
+Input: s = " "
+Output: true
+Explanation: s is an empty string "" after removing non-alphanumeric characters.
+Since an empty string reads the same forward and backward, it is a palindrome.
+
+## Constraints:
+
+ 1 <= s.length <= 2 * 105
+ s consists only of printable ASCII characters.
\ No newline at end of file
diff --git a/csharp/2-TwoPointers/testCases/2_TwoPointersTest.csproj b/csharp/2-TwoPointers/testCases/2_TwoPointersTest.csproj
new file mode 100644
index 000000000..953e7e155
--- /dev/null
+++ b/csharp/2-TwoPointers/testCases/2_TwoPointersTest.csproj
@@ -0,0 +1,22 @@
+
+
+
+ net8.0
+ enable
+ false
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/csharp/2-TwoPointers/testCases/N1-L125-ValidPalindrome_Test.cs b/csharp/2-TwoPointers/testCases/N1-L125-ValidPalindrome_Test.cs
new file mode 100644
index 000000000..96ac5c260
--- /dev/null
+++ b/csharp/2-TwoPointers/testCases/N1-L125-ValidPalindrome_Test.cs
@@ -0,0 +1,51 @@
+using FluentAssertions;
+using NUnit.Framework;
+using TwoPointers.Main.ValidPalindrome;
+
+namespace testCases
+{
+ public class ValidPalindrome_Test
+ {
+
+ [Test]
+ public void Test_Example_1()
+ {
+ // Arrange
+ string input = "A man, a plan, a canal: Panama";
+ // Act
+ Solution solution = new Solution();
+ bool testResult = solution.IsPalindrome(input);
+
+ // Assert
+ testResult.Should().Be(true);
+ }
+
+ [Test]
+ public void Test_Example_2()
+ {
+ // Given
+ string input = "race a car";
+
+ // When
+ Solution solution = new Solution();
+ bool testResult = solution.IsPalindromeInsane(input);
+
+ // Then
+ testResult.Should().Be(false);
+ }
+
+ [Test]
+ public void Test_Example_3()
+ {
+ // Given
+ string input = " ";
+
+ // When
+ Solution solution = new Solution();
+ bool testResult = solution.IsPalindrome(input);
+
+ // Then
+ testResult.Should().Be(true);
+ }
+ }
+}
\ No newline at end of file
diff --git a/csharp/3-SlidingWindow/build.proj b/csharp/3-SlidingWindow/build.proj
new file mode 100644
index 000000000..f63ef53ad
--- /dev/null
+++ b/csharp/3-SlidingWindow/build.proj
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/csharp/3-SlidingWindow/main/3_SlidingWindow.csproj b/csharp/3-SlidingWindow/main/3_SlidingWindow.csproj
new file mode 100644
index 000000000..d2b0a5fab
--- /dev/null
+++ b/csharp/3-SlidingWindow/main/3_SlidingWindow.csproj
@@ -0,0 +1,10 @@
+
+
+
+ net8.0
+ enable
+ enable
+ false
+
+
+
diff --git a/csharp/3-SlidingWindow/main/N1-L121-BestTime4Stocks/Solution.cs b/csharp/3-SlidingWindow/main/N1-L121-BestTime4Stocks/Solution.cs
new file mode 100644
index 000000000..32d2217e2
--- /dev/null
+++ b/csharp/3-SlidingWindow/main/N1-L121-BestTime4Stocks/Solution.cs
@@ -0,0 +1,32 @@
+namespace SlidingWindow.Main.BestTime4Stocks
+{
+ public class Solution
+ {
+ // time complexity : O(n), n = prices.length, bc only go through the array once
+ // space complexity : O(1), because you are using pointers
+ public int MaxProfit(int[] prices)
+ {
+ int buyDay = 0; // left pointer
+ int sellDay = 1; // right pointer
+ int maxProfit = 0;
+
+ while (sellDay < prices.Length)
+ {
+ // check if current transaction can be profitable
+ if (prices[buyDay] < prices[sellDay])
+ {
+ // calculate revenue
+ int currentProfit = prices[sellDay] - prices[buyDay];
+ // update max possible profit if needed be
+ maxProfit = Math.Max(maxProfit, currentProfit);
+ }
+ else
+ buyDay = sellDay;
+
+ sellDay++;
+ }
+
+ return maxProfit;
+ }
+ }
+}
\ No newline at end of file
diff --git a/csharp/3-SlidingWindow/main/N1-L121-BestTime4Stocks/readme.md b/csharp/3-SlidingWindow/main/N1-L121-BestTime4Stocks/readme.md
new file mode 100644
index 000000000..d9e5a0444
--- /dev/null
+++ b/csharp/3-SlidingWindow/main/N1-L121-BestTime4Stocks/readme.md
@@ -0,0 +1,30 @@
+# N1-L121. Best Time to Buy and Sell Stock
+
+Easy
+
+You are given an array prices where prices[i] is the price of a given stock on the ith day.
+
+You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.
+
+Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.
+
+
+## Example 1:
+
+Input: prices = [7,1,5,3,6,4]
+Output: 5
+Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
+Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.
+
+## Example 2:
+
+Input: prices = [7,6,4,3,1]
+Output: 0
+Explanation: In this case, no transactions are done and the max profit = 0.
+
+
+## Constraints:
+
+ 1 <= prices.length <= 105
+ 0 <= prices[i] <= 104
+
diff --git a/csharp/3-SlidingWindow/testCases/3_SlidingWindowTest.csproj b/csharp/3-SlidingWindow/testCases/3_SlidingWindowTest.csproj
new file mode 100644
index 000000000..832d2d533
--- /dev/null
+++ b/csharp/3-SlidingWindow/testCases/3_SlidingWindowTest.csproj
@@ -0,0 +1,22 @@
+
+
+
+ net8.0
+ enable
+ false
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/csharp/3-SlidingWindow/testCases/N1-L121-BestTime4Stocks_Test.cs b/csharp/3-SlidingWindow/testCases/N1-L121-BestTime4Stocks_Test.cs
new file mode 100644
index 000000000..a7a8ea2dc
--- /dev/null
+++ b/csharp/3-SlidingWindow/testCases/N1-L121-BestTime4Stocks_Test.cs
@@ -0,0 +1,32 @@
+
+using FluentAssertions;
+using NUnit.Framework;
+using SlidingWindow.Main.BestTime4Stocks;
+
+namespace testCases;
+
+public class BestTime4Stocks_Test
+{
+
+ [Test]
+ public void Test_Example_1()
+ {
+ int[] prices = {7, 1, 5, 3, 6, 4};
+
+ Solution solution = new Solution();
+ int testResult = solution.MaxProfit(prices);
+
+ testResult.Should().Be(5);
+ }
+
+ [Test]
+ public void Test_Example_2()
+ {
+ int[] prices = { 7, 6, 4, 3, 1 };
+
+ Solution solution = new Solution();
+ int testResult = solution.MaxProfit(prices);
+
+ testResult.Should().Be(0);
+ }
+}
\ No newline at end of file
diff --git a/csharp/4-Stack/main/4_Stack.csproj b/csharp/4-Stack/main/4_Stack.csproj
new file mode 100644
index 000000000..d2b0a5fab
--- /dev/null
+++ b/csharp/4-Stack/main/4_Stack.csproj
@@ -0,0 +1,10 @@
+
+
+
+ net8.0
+ enable
+ enable
+ false
+
+
+
diff --git a/csharp/4-Stack/main/N1-L20-ValidParentheses/Solution.cs b/csharp/4-Stack/main/N1-L20-ValidParentheses/Solution.cs
new file mode 100644
index 000000000..14bfdc8f4
--- /dev/null
+++ b/csharp/4-Stack/main/N1-L20-ValidParentheses/Solution.cs
@@ -0,0 +1,38 @@
+namespace Stack.Main.ValidParentheses
+{
+ public class Solution
+ {
+ // time complexity : O(n) <-- string is traversed only once
+ // space complexity : O(n) <-- max size of the stack
+ public bool IsValid(string s)
+ {
+
+ if (s.Length %2 != 0)
+ return false;
+
+ Stack stack = new();
+ Dictionary closeOpenBracketsMatch = new()
+ {
+ {')','('},
+ {']','['},
+ {'}','{'}
+ };
+
+ foreach (char c in s)
+ {
+ if (closeOpenBracketsMatch.ContainsKey(c))
+ {
+ if (stack.Count != 0 && stack.Peek() == closeOpenBracketsMatch[c])
+ stack.Pop();
+ else
+ return false;
+ }
+ else
+ stack.Push(c);
+ }
+
+ return stack.Count == 0;
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/csharp/4-Stack/main/N1-L20-ValidParentheses/readme.md b/csharp/4-Stack/main/N1-L20-ValidParentheses/readme.md
new file mode 100644
index 000000000..1845b51ba
--- /dev/null
+++ b/csharp/4-Stack/main/N1-L20-ValidParentheses/readme.md
@@ -0,0 +1,33 @@
+# N1-L20. Valid Parentheses
+Easy
+
+Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
+
+An input string is valid if:
+
+ Open brackets must be closed by the same type of brackets.
+ Open brackets must be closed in the correct order.
+
+
+## Example 1:
+
+Input: s = "()"
+Output: true
+
+## Example 2:
+
+Input: s = "()[]{}"
+Output: true
+
+## Example 3:
+
+Input: s = "(]"
+Output: false
+
+
+
+Constraints:
+
+ 1 <= s.length <= 104
+ s consists of parentheses only '()[]{}'.
+
diff --git a/csharp/4-Stack/main/N2-L155-MinStack/Solution.cs b/csharp/4-Stack/main/N2-L155-MinStack/Solution.cs
new file mode 100644
index 000000000..9f9084248
--- /dev/null
+++ b/csharp/4-Stack/main/N2-L155-MinStack/Solution.cs
@@ -0,0 +1,49 @@
+namespace Stack.Main.MinStack
+{
+ // All operations in this class are O(1) in time,
+ // thanks to the Stack capabilities.
+ // That's why we add a second one for the minima
+ public class MinStack
+ {
+ private Stack _stack ;
+
+ private Stack _minStack;
+ public MinStack()
+ {
+ _stack = new();
+ _minStack = new();
+ }
+
+ public void Push(int val)
+ {
+ _stack.Push(val);
+ val = _minStack.TryPeek(out int currentMin) ? Math.Min(val,currentMin) : val;
+ _minStack.Push(val);
+ }
+
+ public void Pop()
+ {
+ _stack.Pop();
+ _minStack.Pop();
+ }
+
+ public int Top()
+ {
+ return _stack.Peek();
+ }
+
+ public int GetMin()
+ {
+ return _minStack.Peek();
+ }
+ }
+
+ /**
+ * Your MinStack object will be instantiated and called as such:
+ * MinStack obj = new MinStack();
+ * obj.Push(val);
+ * obj.Pop();
+ * int param_3 = obj.Top();
+ * int param_4 = obj.GetMin();
+ */
+}
\ No newline at end of file
diff --git a/csharp/4-Stack/main/N2-L155-MinStack/readme.md b/csharp/4-Stack/main/N2-L155-MinStack/readme.md
new file mode 100644
index 000000000..60b129426
--- /dev/null
+++ b/csharp/4-Stack/main/N2-L155-MinStack/readme.md
@@ -0,0 +1,29 @@
+# N2-L155. MinStack
+Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
+
+Implement the MinStack class:
+
+ MinStack() initializes the stack object.
+ void push(int val) pushes the element val onto the stack.
+ void pop() removes the element on the top of the stack.
+ int top() gets the top element of the stack.
+ int getMin() retrieves the minimum element in the stack.
+
+## Example 1:
+
+### Input
+["MinStack","push","push","push","getMin","pop","top","getMin"]
+[[], [-2], [0], [-3], [], [], [], []]
+
+### Output
+[null,null,null,null,-3,null,0,-2]
+
+### Explanation
+MinStack minStack = new MinStack();
+minStack.push(-2);
+minStack.push(0);
+minStack.push(-3);
+minStack.getMin(); // return -3
+minStack.pop();
+minStack.top(); // return 0
+minStack.getMin(); // return -2
diff --git a/csharp/4-Stack/testCases/4_StackTest.csproj b/csharp/4-Stack/testCases/4_StackTest.csproj
new file mode 100644
index 000000000..6730e6e42
--- /dev/null
+++ b/csharp/4-Stack/testCases/4_StackTest.csproj
@@ -0,0 +1,22 @@
+
+
+
+ net8.0
+ enable
+ false
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/csharp/4-Stack/testCases/N1-L20-ValidParentheses_Test.cs b/csharp/4-Stack/testCases/N1-L20-ValidParentheses_Test.cs
new file mode 100644
index 000000000..f35a8b165
--- /dev/null
+++ b/csharp/4-Stack/testCases/N1-L20-ValidParentheses_Test.cs
@@ -0,0 +1,54 @@
+using FluentAssertions;
+using NUnit.Framework;
+using Stack.Main;
+using Stack.Main.ValidParentheses;
+
+namespace testCases;
+
+public class ValidParentheses_Tests
+{
+
+ [Test]
+ public void Test_Example_1()
+ {
+ string input = "()";
+
+ Solution solution = new();
+ bool testResult = solution.IsValid(input);
+
+ testResult.Should().Be(true);
+ }
+
+ [Test]
+ public void Test_Example_2()
+ {
+ string input = "()[]{}";
+
+ Solution solution = new();
+ bool testResult = solution.IsValid(input);
+
+ testResult.Should().Be(true);
+ }
+
+ [Test]
+ public void Test_Example_3()
+ {
+ string input = "(]";
+
+ Solution solution = new();
+ bool testResult = solution.IsValid(input);
+
+ testResult.Should().Be(false);
+ }
+
+ [Test]
+ public void Test_Example_4()
+ {
+ string input = "{[()]}";
+
+ Solution solution = new();
+ bool testResult = solution.IsValid(input);
+
+ testResult.Should().Be(true);
+ }
+}
\ No newline at end of file
diff --git a/csharp/5-BinarySearch/build.proj b/csharp/5-BinarySearch/build.proj
new file mode 100644
index 000000000..f63ef53ad
--- /dev/null
+++ b/csharp/5-BinarySearch/build.proj
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/csharp/5-BinarySearch/main/5_BinarySearch.csproj b/csharp/5-BinarySearch/main/5_BinarySearch.csproj
new file mode 100644
index 000000000..d2b0a5fab
--- /dev/null
+++ b/csharp/5-BinarySearch/main/5_BinarySearch.csproj
@@ -0,0 +1,10 @@
+
+
+
+ net8.0
+ enable
+ enable
+ false
+
+
+
diff --git a/csharp/5-BinarySearch/main/N1-L704-BinarySearch/Solution.cs b/csharp/5-BinarySearch/main/N1-L704-BinarySearch/Solution.cs
new file mode 100644
index 000000000..47bbda746
--- /dev/null
+++ b/csharp/5-BinarySearch/main/N1-L704-BinarySearch/Solution.cs
@@ -0,0 +1,33 @@
+namespace BinarySearch.Main.BinarySearch
+{
+ public class Solution
+ {
+
+ // - time complexity: O(log n) bc if you start with n values in the array
+ // and then you don't find the target, in the next step you have n/2 possibilities to examine,
+ // then n/4 and so on. So in the worst case scenario, before you reach 1,
+ // you need to iterate as many times as you can divide n by 2, which is precisely log_2(n)
+ public int Search(int[] nums, int target)
+ {
+ int leftPt = 0;
+ int rightPt = nums.Length - 1;
+
+ while (leftPt <= rightPt)
+ {
+ // use this definition instead of
+ // (rightPt + leftPt) / 2
+ // to avoid overflow
+ int indexAtHalf = leftPt + ((rightPt - leftPt) / 2);
+
+ if (target > nums[indexAtHalf])
+ leftPt = indexAtHalf + 1;
+ else if (target < nums[indexAtHalf])
+ rightPt = indexAtHalf - 1;
+ else
+ return indexAtHalf;
+ }
+
+ return -1;
+ }
+ }
+}
\ No newline at end of file
diff --git a/csharp/5-BinarySearch/main/N1-L704-BinarySearch/readme.md b/csharp/5-BinarySearch/main/N1-L704-BinarySearch/readme.md
new file mode 100644
index 000000000..677a94845
--- /dev/null
+++ b/csharp/5-BinarySearch/main/N1-L704-BinarySearch/readme.md
@@ -0,0 +1,30 @@
+# N1-L7704. Binary Search
+Easy
+
+Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums.
+If target exists, then return its index. Otherwise, return -1.
+
+You must write an algorithm with **O(log n) runtime complexity**
+
+
+
+## Example 1:
+
+Input: nums = [-1,0,3,5,9,12], target = 9
+Output: 4
+Explanation: 9 exists in nums and its index is 4
+
+## Example 2:
+
+Input: nums = [-1,0,3,5,9,12], target = 2
+Output: -1
+Explanation: 2 does not exist in nums so return -1
+
+
+## Constraints:
+
+ 1 <= nums.length <= 104
+ -104 < nums[i], target < 104
+ All the integers in nums are unique.
+ nums is sorted in ascending order.
+
diff --git a/csharp/5-BinarySearch/testCases/5_BinarySearchTest.csproj b/csharp/5-BinarySearch/testCases/5_BinarySearchTest.csproj
new file mode 100644
index 000000000..594999c3a
--- /dev/null
+++ b/csharp/5-BinarySearch/testCases/5_BinarySearchTest.csproj
@@ -0,0 +1,22 @@
+
+
+
+ net8.0
+ enable
+ false
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/csharp/5-BinarySearch/testCases/N1-L704-BinarySearch.cs b/csharp/5-BinarySearch/testCases/N1-L704-BinarySearch.cs
new file mode 100644
index 000000000..3ea499d3c
--- /dev/null
+++ b/csharp/5-BinarySearch/testCases/N1-L704-BinarySearch.cs
@@ -0,0 +1,33 @@
+using NUnit.Framework;
+using FluentAssertions;
+using BinarySearch.Main.BinarySearch;
+
+namespace testCases;
+
+public class BinarySearch_Test
+{
+
+ [Test]
+ public void Test_Example_1()
+ {
+ int[] inputNums = {-1, 0, 3, 5, 9, 12};
+ int target = 9;
+
+ Solution solution = new();
+ int testResult = solution.Search(inputNums,target);
+
+ testResult.Should().Be(4);
+ }
+
+ [Test]
+ public void Test_Example_2()
+ {
+ int[] inputNums = { -1, 0, 3, 5, 9, 12 };
+ int target = 2;
+
+ Solution solution = new();
+ int testResult = solution.Search(inputNums, target);
+
+ testResult.Should().Be(-1);
+ }
+}
\ No newline at end of file
diff --git a/csharp/6_LinkedList/6_LinkedList.csproj b/csharp/6_LinkedList/6_LinkedList.csproj
new file mode 100644
index 000000000..3a6353295
--- /dev/null
+++ b/csharp/6_LinkedList/6_LinkedList.csproj
@@ -0,0 +1,9 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
diff --git a/csharp/6_LinkedList/N1-L206-ReverseLinkedList/Solution.cs b/csharp/6_LinkedList/N1-L206-ReverseLinkedList/Solution.cs
new file mode 100644
index 000000000..7fd02e544
--- /dev/null
+++ b/csharp/6_LinkedList/N1-L206-ReverseLinkedList/Solution.cs
@@ -0,0 +1,55 @@
+namespace LinkedList.Main.ReverseList
+{
+ // Definition for singly-linked list.
+ public class ListNode
+ {
+ public int val;
+ public ListNode next;
+ public ListNode(int val = 0, ListNode next = null)
+ {
+ this.val = val;
+ this.next = next;
+ }
+ }
+
+ public class Solution
+ {
+ // Iterative
+ // TC : O(n)
+ // SC : O(1)
+ public ListNode ReverseListIteratively(ListNode head)
+ {
+ ListNode previous = null;
+ ListNode current = head;
+
+ while (current is not null)
+ {
+ ListNode next = current.next;
+ current.next = previous;
+ previous = current;
+ current = next;
+ }
+
+ return previous;
+ }
+
+ // recursive
+ // TC : O(n)
+ // SC : O(n),
+ public ListNode ReverseListRecursively(ListNode head)
+ {
+ if (head is null)
+ return head;
+
+ ListNode newHead = head;
+ if (head.next is not null)
+ {
+ newHead = ReverseListRecursively(head.next);
+ head.next.next = head;
+ }
+ head.next = null;
+
+ return newHead;
+ }
+ }
+}
diff --git a/csharp/6_LinkedList/N1-L206-ReverseLinkedList/readme.md b/csharp/6_LinkedList/N1-L206-ReverseLinkedList/readme.md
new file mode 100644
index 000000000..7e4cc25ee
--- /dev/null
+++ b/csharp/6_LinkedList/N1-L206-ReverseLinkedList/readme.md
@@ -0,0 +1,27 @@
+# N1-L206. ReverseLinkedList
+
+Given the head of a singly linked list, reverse the list, and return the reversed list.
+
+## Example 1:
+
+
+
+Input: head = [1,2,3,4,5]
+Output: [5,4,3,2,1]
+
+## Example 2:
+
+
+
+Input: head = [1,2]
+Output: [2,1]
+
+## Example 3:
+
+Input: head = []
+Output: []
+
+## Constraints:
+
+ The number of nodes in the list is the range [0, 5000].
+ -5000 <= Node.val <= 5000
diff --git a/csharp/6_LinkedList/N1-L206-ReverseLinkedList/rev1ex1.jpg b/csharp/6_LinkedList/N1-L206-ReverseLinkedList/rev1ex1.jpg
new file mode 100644
index 000000000..697bf935d
Binary files /dev/null and b/csharp/6_LinkedList/N1-L206-ReverseLinkedList/rev1ex1.jpg differ
diff --git a/csharp/6_LinkedList/N1-L206-ReverseLinkedList/rev1ex2.jpg b/csharp/6_LinkedList/N1-L206-ReverseLinkedList/rev1ex2.jpg
new file mode 100644
index 000000000..a50261a97
Binary files /dev/null and b/csharp/6_LinkedList/N1-L206-ReverseLinkedList/rev1ex2.jpg differ
diff --git a/csharp/6_LinkedList/N2-L21-MergedTwoSortedListed/Solution.cs b/csharp/6_LinkedList/N2-L21-MergedTwoSortedListed/Solution.cs
new file mode 100644
index 000000000..e0209f35a
--- /dev/null
+++ b/csharp/6_LinkedList/N2-L21-MergedTwoSortedListed/Solution.cs
@@ -0,0 +1,62 @@
+/**
+ * Definition for singly-linked list.
+ * public class ListNode {
+ * public int val;
+ * public ListNode next;
+ * public ListNode(int val=0, ListNode next=null) {
+ * this.val = val;
+ * this.next = next;
+ * }
+ * }
+ */
+
+namespace LinkedList.Main.MergeTwoLists
+{
+ // Definition for singly-linked list.
+ public class ListNode
+ {
+ public int val;
+ public ListNode next;
+ public ListNode(int val = 0, ListNode next = null)
+ {
+ this.val = val;
+ this.next = next;
+ }
+ }
+ public class Solution
+ {
+
+ public ListNode MergeTwoLists(ListNode list1, ListNode list2)
+ {
+ if (list1 == null && list2 == null)
+ return null;
+
+ ListNode dummy = new();
+ ListNode tail = dummy;
+
+ while (list1 != null && list2 != null)
+ {
+ if (list1.val < list2.val)
+ {
+ tail.next = list1;
+ list1 = list1.next;
+ }
+ else
+ {
+ tail.next = list2;
+ list2 = list2.next;
+ }
+ tail = tail.next;
+ }
+
+ if (list1 is not null)
+ tail.next = list1;
+ else if (list2 is not null)
+ {
+ tail.next = list2;
+ }
+
+ return dummy.next;
+ }
+ }
+}
diff --git a/csharp/6_LinkedList/N2-L21-MergedTwoSortedListed/img1.png b/csharp/6_LinkedList/N2-L21-MergedTwoSortedListed/img1.png
new file mode 100644
index 000000000..2406ab557
Binary files /dev/null and b/csharp/6_LinkedList/N2-L21-MergedTwoSortedListed/img1.png differ
diff --git a/csharp/6_LinkedList/N2-L21-MergedTwoSortedListed/readme.md b/csharp/6_LinkedList/N2-L21-MergedTwoSortedListed/readme.md
new file mode 100644
index 000000000..a89a6c9d9
--- /dev/null
+++ b/csharp/6_LinkedList/N2-L21-MergedTwoSortedListed/readme.md
@@ -0,0 +1,33 @@
+# N2-L21. Merge Two Sorted Lists
+Easy
+
+You are given the heads of two sorted linked lists list1 and list2.
+
+Merge the two lists in a one sorted list. The list should be made by splicing together the nodes of the first two lists.
+
+Return the head of the merged linked list.
+
+## Example 1
+
+
+
+Input: list1 = [1,2,4], list2 = [1,3,4]
+Output: [1,1,2,3,4,4]
+
+## Example 2
+
+Input: list1 = [], list2 = []
+Output: []
+
+## Example 3
+
+Input: list1 = [], list2 = [0]
+Output: [0]
+
+
+
+Constraints:
+
+ The number of nodes in both lists is in the range [0, 50].
+ -100 <= Node.val <= 100
+ Both list1 and list2 are sorted in non-decreasing order.
diff --git a/csharp/6_LinkedList/N3-L141-LinkedListCycle/Solution.cs b/csharp/6_LinkedList/N3-L141-LinkedListCycle/Solution.cs
new file mode 100644
index 000000000..60c88bb59
--- /dev/null
+++ b/csharp/6_LinkedList/N3-L141-LinkedListCycle/Solution.cs
@@ -0,0 +1,47 @@
+namespace LinkedList.Main.LinkedListCycle
+{
+ // WARNING - this definition is slightly different than the one in N1 and N2 :
+ // the constructor only takes one arg
+ // Definition for singly-linked list.
+ public class ListNode
+ {
+ public int val;
+ public ListNode next;
+ public ListNode(int x)
+ {
+ val = x;
+ next = null;
+ }
+ }
+
+ // Hashset sol takes
+ // time : O(n)
+ // space : O(n)
+
+
+ // Floyd's tortoise and hare
+ // if there is a cycle, the slow and the fast pointer they meet again
+ // time : O(n)
+ public class Solution
+ {
+ public bool HasCycle(ListNode head)
+ {
+ ListNode slow = head;
+ ListNode fast = head;
+
+ while (fast is not null && fast.next is not null)
+ {
+ slow = slow.next;
+ fast = fast.next.next;
+ if (slow == fast)
+ return true;
+ }
+
+ return false;
+ }
+ }
+}
+
+
+
+
diff --git a/csharp/6_LinkedList/N3-L141-LinkedListCycle/circularlinkedlis1t.png b/csharp/6_LinkedList/N3-L141-LinkedListCycle/circularlinkedlis1t.png
new file mode 100644
index 000000000..b0111ae63
Binary files /dev/null and b/csharp/6_LinkedList/N3-L141-LinkedListCycle/circularlinkedlis1t.png differ
diff --git a/csharp/6_LinkedList/N3-L141-LinkedListCycle/circularlinkedlist2.png b/csharp/6_LinkedList/N3-L141-LinkedListCycle/circularlinkedlist2.png
new file mode 100644
index 000000000..634e7a47f
Binary files /dev/null and b/csharp/6_LinkedList/N3-L141-LinkedListCycle/circularlinkedlist2.png differ
diff --git a/csharp/6_LinkedList/N3-L141-LinkedListCycle/readme.md b/csharp/6_LinkedList/N3-L141-LinkedListCycle/readme.md
new file mode 100644
index 000000000..9044b04cf
--- /dev/null
+++ b/csharp/6_LinkedList/N3-L141-LinkedListCycle/readme.md
@@ -0,0 +1,36 @@
+# L141. Linked List Cycle
+Easy
+
+Given head, the head of a linked list, determine if the linked list has a cycle in it.
+
+There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to. Note that pos is not passed as a parameter.
+
+Return true if there is a cycle in the linked list. Otherwise, return false.
+
+## Example 1:
+
+
+
+Input: head = [3,2,0,-4], pos = 1
+Output: true
+Explanation: There is a cycle in the linked list, where the tail connects to the 1st node (0-indexed).
+
+## Example 2:
+
+
+
+Input: head = [1,2], pos = 0
+Output: true
+Explanation: There is a cycle in the linked list, where the tail connects to the 0th node.
+
+## Example 3:
+
+Input: head = [1], pos = -1
+Output: false
+Explanation: There is no cycle in the linked list.
+
+## Constraints:
+
+ The number of the nodes in the list is in the range [0, 104].
+ -105 <= Node.val <= 105
+ pos is -1 or a valid index in the linked-list.
diff --git a/csharp/6_LinkedListTests/6_LinkedListTests.csproj b/csharp/6_LinkedListTests/6_LinkedListTests.csproj
new file mode 100644
index 000000000..5ef31c814
--- /dev/null
+++ b/csharp/6_LinkedListTests/6_LinkedListTests.csproj
@@ -0,0 +1,29 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+ false
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/csharp/6_LinkedListTests/N1-L206-ReverseLinkedList_Test.cs b/csharp/6_LinkedListTests/N1-L206-ReverseLinkedList_Test.cs
new file mode 100644
index 000000000..42c10c5a8
--- /dev/null
+++ b/csharp/6_LinkedListTests/N1-L206-ReverseLinkedList_Test.cs
@@ -0,0 +1,60 @@
+using FluentAssertions;
+using LinkedList.Main.ReverseList;
+
+namespace testCases;
+
+public class ReverseLinkedList_Test
+{
+ [Test]
+ public void Test_Example_1_Recursively()
+ {
+ ListNode input = new(1, new(2, new(3, new(4, new(5)))));
+
+ Solution solution = new();
+ ListNode testResult = solution.ReverseListRecursively(input);
+
+ testResult.val.Should().Be(5);
+ testResult.next.val.Should().Be(4);
+ testResult.next.next.val.Should().Be(3);
+ testResult.next.next.next.val.Should().Be(2);
+ testResult.next.next.next.next.val.Should().Be(1);
+ }
+
+ [Test]
+ public void Test_Example_1_Iteratively()
+ {
+ ListNode input = new(1, new(2, new(3, new(4, new(5)))));
+
+ Solution solution = new();
+ ListNode testResult = solution.ReverseListIteratively(input);
+
+ testResult.val.Should().Be(5);
+ testResult.next.val.Should().Be(4);
+ testResult.next.next.val.Should().Be(3);
+ testResult.next.next.next.val.Should().Be(2);
+ testResult.next.next.next.next.val.Should().Be(1);
+ }
+
+ [Test]
+ public void Test_Example_2()
+ {
+ ListNode input = new(1, new(2));
+
+ Solution solution = new();
+ ListNode testResult = solution.ReverseListRecursively(input);
+
+ testResult.val.Should().Be(2);
+ testResult.next.val.Should().Be(1);
+ }
+
+ [Test]
+ public void Test_Example_3()
+ {
+ ListNode input = null;
+
+ Solution solution = new();
+ ListNode testResult = solution.ReverseListRecursively(input);
+
+ testResult.Should().BeNull();
+ }
+}
\ No newline at end of file
diff --git a/csharp/6_LinkedListTests/N2-L21-MergeTwoLists_Test.cs b/csharp/6_LinkedListTests/N2-L21-MergeTwoLists_Test.cs
new file mode 100644
index 000000000..a4740f0a2
--- /dev/null
+++ b/csharp/6_LinkedListTests/N2-L21-MergeTwoLists_Test.cs
@@ -0,0 +1,47 @@
+using FluentAssertions;
+using LinkedList.Main.MergeTwoLists;
+
+namespace testCases
+{
+ public class MergeTwoLinkedList_Test
+ {
+ [Test]
+ public void Test_Example_1()
+ {
+ ListNode input1 = new(1, new(2, new(4)));
+ ListNode input2 = new(1, new(3, new(4)));
+
+ Solution solution = new();
+ ListNode testResult = solution.MergeTwoLists(input1,input2);
+
+ testResult.val.Should().Be(1);
+ testResult.next.val.Should().Be(1);
+ testResult.next.next.val.Should().Be(2);
+ testResult.next.next.next.val.Should().Be(3);
+ testResult.next.next.next.next.val.Should().Be(4);
+ testResult.next.next.next.next.next.val.Should().Be(4);
+ }
+
+ [Test]
+ public void Test_Example_2()
+ {
+ Solution solution = new();
+ ListNode testResult = solution.MergeTwoLists(null,null);
+
+ testResult.Should().Be(null);
+ }
+
+ [Test]
+ public void Test_Example_3()
+ {
+ ListNode input2 = new(0);
+
+ Solution solution = new();
+ ListNode testResult = solution.MergeTwoLists(null, input2);
+
+ testResult.val.Should().Be(null);
+
+ }
+ }
+}
+
diff --git a/csharp/6_LinkedListTests/N3-L141-LinkedListCycle.cs b/csharp/6_LinkedListTests/N3-L141-LinkedListCycle.cs
new file mode 100644
index 000000000..f8dfcaf99
--- /dev/null
+++ b/csharp/6_LinkedListTests/N3-L141-LinkedListCycle.cs
@@ -0,0 +1,61 @@
+using FluentAssertions;
+using LinkedList.Main.LinkedListCycle;
+using NUnit.Framework;
+
+namespace testCases
+{
+ public class LinkedListCycle_Test
+ {
+ [Test]
+ public void Test_Example_1()
+ {
+ ListNode headNode = new(3);
+ headNode.next = new(2);
+ headNode.next.next = new(0);
+ ListNode last = headNode.next.next.next = new(-4);
+ // cycle
+ last.next = headNode.next;
+
+ Solution solution = new();
+ bool testResult = solution.HasCycle(headNode);
+
+ testResult.Should().Be(true);
+ }
+
+ [Test]
+ public void Test_Example_2()
+ {
+ ListNode headNode = new(1);
+ headNode.next = new(2);
+ headNode.next.next = headNode;
+
+ Solution solution = new();
+ bool testResult = solution.HasCycle(headNode);
+
+ testResult.Should().Be(true);
+ }
+
+ [Test]
+ public void Test_Example_3()
+ {
+ ListNode headNode = new(1);
+
+ Solution solution = new();
+ bool testResult = solution.HasCycle(headNode);
+
+ testResult.Should().Be(false);
+ }
+
+ [Test]
+ public void Test_Example_FailedSubmission()
+ {
+ ListNode headNode = new(1);
+ headNode.next = new(2);
+
+ Solution solution = new();
+ bool testResult = solution.HasCycle(headNode);
+
+ testResult.Should().Be(false);
+ }
+ }
+}
\ No newline at end of file
diff --git a/csharp/7_LinkedListTests/7_LinkedListTests.csproj b/csharp/7_LinkedListTests/7_LinkedListTests.csproj
new file mode 100644
index 000000000..67bd92b2b
--- /dev/null
+++ b/csharp/7_LinkedListTests/7_LinkedListTests.csproj
@@ -0,0 +1,25 @@
+
+
+
+ net8.0
+ _7_LinkedListTests
+ enable
+ enable
+
+ false
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/csharp/7_Tree/7_Tree.csproj b/csharp/7_Tree/7_Tree.csproj
new file mode 100644
index 000000000..3a6353295
--- /dev/null
+++ b/csharp/7_Tree/7_Tree.csproj
@@ -0,0 +1,9 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
diff --git a/csharp/7_Tree/BinaryTree.cs b/csharp/7_Tree/BinaryTree.cs
new file mode 100644
index 000000000..6189afc45
--- /dev/null
+++ b/csharp/7_Tree/BinaryTree.cs
@@ -0,0 +1,19 @@
+using BinaryTree.Main;
+
+namespace BinaryTree.Main
+{
+ public class TreeNode
+ {
+ public int val;
+ public TreeNode left;
+ public TreeNode right;
+ public TreeNode(int val = 0, TreeNode left = null, TreeNode right = null)
+ {
+ this.val = val;
+ this.left = left;
+ this.right = right;
+ }
+ }
+
+}
+
diff --git a/csharp/7_Tree/N1-L226-InvertBinaryTree/Solution.cs b/csharp/7_Tree/N1-L226-InvertBinaryTree/Solution.cs
new file mode 100644
index 000000000..2e8256289
--- /dev/null
+++ b/csharp/7_Tree/N1-L226-InvertBinaryTree/Solution.cs
@@ -0,0 +1,26 @@
+namespace BinaryTree.Main.InvertBinaryTree
+{
+ // MAIN IDEA :
+ // recursively visit each node and swap its children
+ // Use Depth First Search (DFS)
+ // Time Complexity: O(n), where n is the number of nodes in the binary tree. We are visiting each node once, hence the time complexity is linear.
+ // Space Complexity: O(h), where h is the height of the binary tree
+ public class Solution
+ {
+ public TreeNode InvertTree(TreeNode root)
+ {
+ if (root == null)
+ return null;
+
+ (root.left, root.right) = (root.right, root.left);
+
+ InvertTree(root.left);
+ InvertTree(root.right);
+
+ return root;
+ }
+ }
+
+}
+
+
diff --git a/csharp/7_Tree/N1-L226-InvertBinaryTree/readme.md b/csharp/7_Tree/N1-L226-InvertBinaryTree/readme.md
new file mode 100644
index 000000000..fa4f411e1
--- /dev/null
+++ b/csharp/7_Tree/N1-L226-InvertBinaryTree/readme.md
@@ -0,0 +1,27 @@
+# Invert Binary Tree
+
+You are given the root of a binary tree root. Invert the binary tree and return its root.
+
+## Example 1
+
+
+
+Input: root = [1,2,3,4,5,6,7]
+Output: [1,3,2,7,6,5,4]
+
+## Example 2
+
+Input: root = [3,2,1]
+Output: [3,1,2]
+
+
+
+## Example 3
+
+Input: root = []
+Output: []
+
+## Constraints:
+
+- 0 <= The number of nodes in the tree <= 100
+- -100 <= Node.val <= 100
diff --git a/csharp/7_Tree/N1-L226-InvertBinaryTree/res/img.png b/csharp/7_Tree/N1-L226-InvertBinaryTree/res/img.png
new file mode 100644
index 000000000..07a273097
Binary files /dev/null and b/csharp/7_Tree/N1-L226-InvertBinaryTree/res/img.png differ
diff --git a/csharp/7_Tree/N1-L226-InvertBinaryTree/res/img2.png b/csharp/7_Tree/N1-L226-InvertBinaryTree/res/img2.png
new file mode 100644
index 000000000..9e1b07d82
Binary files /dev/null and b/csharp/7_Tree/N1-L226-InvertBinaryTree/res/img2.png differ
diff --git a/csharp/7_Tree/N2-L104-MaximumDepthOfBinaryTree/Solution.cs b/csharp/7_Tree/N2-L104-MaximumDepthOfBinaryTree/Solution.cs
new file mode 100644
index 000000000..3ee6bb606
--- /dev/null
+++ b/csharp/7_Tree/N2-L104-MaximumDepthOfBinaryTree/Solution.cs
@@ -0,0 +1,68 @@
+using System.Collections;
+
+namespace BinaryTree.Main.MaximumDepthBinaryTree
+{
+ public class Solution
+ {
+ //Depth Search First
+ public int MaxDepthDFS(TreeNode root)
+ {
+ if (root is null)
+ return 0;
+
+ return 1 + Math.Max(MaxDepthDFS(root.left), MaxDepthDFS(root.right));
+ }
+
+ // BFS
+ public int MaxDepthBFS(TreeNode root)
+ {
+ if (root is null)
+ return 0;
+
+ var q = new Queue();
+ var treeLevel = 0;
+
+ q.Enqueue(root);
+ while (q.Any())
+ {
+ for (int i = 0; i < q.Count; i++)
+ {
+ var node = q.Dequeue();
+ if (node.left != null)
+ q.Enqueue(node.left);
+ if (node.right != null)
+ q.Enqueue(node.right);
+ }
+
+ treeLevel++;
+ }
+
+ return treeLevel;
+ }
+
+ // Iterative DFS
+ public int MaxDepthIterativeDFS(TreeNode root)
+ {
+ int treeLevel = 0;
+
+ var s = new Stack>();
+ s.Push(new(root, 1));
+
+ while (s.Any())
+ {
+ var current = s.Pop();
+ var node = current.Item1;
+ int depth = current.Item2;
+
+ if (node != null)
+ {
+ treeLevel = Math.Max(treeLevel, depth);
+ s.Push(new Tuple(node.left, depth + 1));
+ s.Push(new Tuple(node.right, depth + 1));
+ }
+ }
+
+ return treeLevel;
+ }
+ }
+}
\ No newline at end of file
diff --git a/csharp/7_Tree/N2-L104-MaximumDepthOfBinaryTree/img.png b/csharp/7_Tree/N2-L104-MaximumDepthOfBinaryTree/img.png
new file mode 100644
index 000000000..cda408012
Binary files /dev/null and b/csharp/7_Tree/N2-L104-MaximumDepthOfBinaryTree/img.png differ
diff --git a/csharp/7_Tree/N2-L104-MaximumDepthOfBinaryTree/readme.md b/csharp/7_Tree/N2-L104-MaximumDepthOfBinaryTree/readme.md
new file mode 100644
index 000000000..7fdd80b0d
--- /dev/null
+++ b/csharp/7_Tree/N2-L104-MaximumDepthOfBinaryTree/readme.md
@@ -0,0 +1,24 @@
+# Maximum Depth of Binary Tree
+
+Given the root of a binary tree, return its depth.
+
+The depth of a binary tree is defined as the number of nodes along the longest path from the root node down to the farthest leaf node.
+
+## Example 1
+
+Input: root = [1,2,3,null,null,4]
+
+
+
+Output: 3
+
+## Example 2
+
+Input: root = []
+
+Output: 0
+
+## Constraints:
+
+- 0 <= The number of nodes in the tree <= 100.
+- -100 <= Node.val <= 100
diff --git a/csharp/7_TreeTests/7_TreeTests.csproj b/csharp/7_TreeTests/7_TreeTests.csproj
new file mode 100644
index 000000000..93396e1ec
--- /dev/null
+++ b/csharp/7_TreeTests/7_TreeTests.csproj
@@ -0,0 +1,29 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+ false
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/csharp/7_TreeTests/InvertBinaryTree_Tests.cs b/csharp/7_TreeTests/InvertBinaryTree_Tests.cs
new file mode 100644
index 000000000..ae6cb1bce
--- /dev/null
+++ b/csharp/7_TreeTests/InvertBinaryTree_Tests.cs
@@ -0,0 +1,31 @@
+using BinaryTree.Main;
+using BinaryTree.Main.InvertBinaryTree;
+using FluentAssertions;
+
+namespace testcases;
+
+public class InvertBinaryTree_Tests
+{
+ [Test]
+ public void Test_Example_1()
+ {
+ TreeNode four = new(4);
+ TreeNode five = new(5);
+ TreeNode six = new(6);
+ TreeNode seven = new(7);
+ TreeNode two = new(2, four, five);
+ TreeNode three = new(3, six, seven);
+ TreeNode one = new(1, two, three);
+
+ var solution = new Solution();
+ TreeNode invertedTree = solution.InvertTree(one);
+
+ invertedTree.val.Should().Be(1);
+ invertedTree.left.val.Should().Be(3);
+ invertedTree.right.val.Should().Be(2);
+ invertedTree.left.left.val.Should().Be(7);
+ invertedTree.left.right.val.Should().Be(6);
+ invertedTree.right.left.val.Should().Be(5);
+ invertedTree.right.right.val.Should().Be(4);
+ }
+}
\ No newline at end of file
diff --git a/csharp/7_TreeTests/N2-L104-MaximuDepth.cs b/csharp/7_TreeTests/N2-L104-MaximuDepth.cs
new file mode 100644
index 000000000..de64160ec
--- /dev/null
+++ b/csharp/7_TreeTests/N2-L104-MaximuDepth.cs
@@ -0,0 +1,53 @@
+using BinaryTree.Main;
+using BinaryTree.Main.MaximumDepthBinaryTree;
+using FluentAssertions;
+
+namespace testcases;
+
+public class MaximuDepthTree_Tests
+{
+ [Test]
+ public void Test_Example_1_DFS()
+ {
+ TreeNode node1 = new TreeNode(7);
+ TreeNode node2 = new TreeNode(15);
+ TreeNode node3 = new TreeNode(20, node2, node1);
+ TreeNode node4 = new TreeNode(9);
+ TreeNode node6 = new TreeNode(3, node4, node3);
+
+ Solution solution = new();
+ int testResult = solution.MaxDepthDFS(node6);
+
+ testResult.Should().Be(3);
+ }
+
+ [Test]
+ public void Test_Example_1_BFS()
+ {
+ TreeNode node1 = new TreeNode(7);
+ TreeNode node2 = new TreeNode(15);
+ TreeNode node3 = new TreeNode(20, node2, node1);
+ TreeNode node4 = new TreeNode(9);
+ TreeNode node6 = new TreeNode(3, node4, node3);
+
+ Solution solution = new();
+ int testResult = solution.MaxDepthBFS(node6);
+
+ testResult.Should().Be(3);
+ }
+
+ [Test]
+ public void Test_Example_1_Iterative_DFS()
+ {
+ TreeNode node1 = new TreeNode(7);
+ TreeNode node2 = new TreeNode(15);
+ TreeNode node3 = new TreeNode(20, node2, node1);
+ TreeNode node4 = new TreeNode(9);
+ TreeNode node6 = new TreeNode(3, node4, node3);
+
+ Solution solution = new();
+ int testResult = solution.MaxDepthIterativeDFS(node6);
+
+ testResult.Should().Be(3);
+ }
+}
\ No newline at end of file
diff --git a/csharp/MakeArrayZeroBySubtractingEqualAmounts/MakeArrayZeroBySubtractingEqualAmounts.csproj b/csharp/MakeArrayZeroBySubtractingEqualAmounts/MakeArrayZeroBySubtractingEqualAmounts.csproj
new file mode 100644
index 000000000..17b910f6d
--- /dev/null
+++ b/csharp/MakeArrayZeroBySubtractingEqualAmounts/MakeArrayZeroBySubtractingEqualAmounts.csproj
@@ -0,0 +1,9 @@
+
+
+
+ net9.0
+ enable
+ enable
+
+
+
diff --git a/csharp/MakeArrayZeroBySubtractingEqualAmounts/ParkingSystem.cs b/csharp/MakeArrayZeroBySubtractingEqualAmounts/ParkingSystem.cs
new file mode 100644
index 000000000..9492807cb
--- /dev/null
+++ b/csharp/MakeArrayZeroBySubtractingEqualAmounts/ParkingSystem.cs
@@ -0,0 +1,40 @@
+public class ParkingSystem
+{
+ private Dictionary SlotAllocation = new();
+
+ public ParkingSystem(int big, int medium, int small)
+ {
+ SlotAllocation[1] = big;
+ SlotAllocation[2] = medium;
+ SlotAllocation[3] = small;
+ }
+
+ public bool AddCar(int carType)
+ {
+ var availableSlotsForCarType = SlotAllocation[carType];
+ if (availableSlotsForCarType > 0)
+ {
+ SlotAllocation[carType] -= 1;
+ return true;
+ }
+
+ return false;
+ }
+}
+
+/**
+ * Your ParkingSystem object will be instantiated and called as such:
+ * ParkingSystem obj = new ParkingSystem(big, medium, small);
+ * bool param_1 = obj.AddCar(carType);
+ */
+
+// fastest solution found on leetcode
+// public class ParkingSystem {
+// private int[] ParkingPlaces { get; }
+//
+// public ParkingSystem(int big, int medium, int small) {
+// ParkingPlaces = new int[] { 0, big, medium, small };
+// }
+//
+// public bool AddCar(int carType) => --ParkingPlaces[carType] >= 0;
+// }
\ No newline at end of file
diff --git a/csharp/MakeArrayZeroBySubtractingEqualAmounts/README.md b/csharp/MakeArrayZeroBySubtractingEqualAmounts/README.md
new file mode 100644
index 000000000..bfd6df2d3
--- /dev/null
+++ b/csharp/MakeArrayZeroBySubtractingEqualAmounts/README.md
@@ -0,0 +1 @@
+List of problems taken from https://leetcode.com/problem-list/7p5x763/
\ No newline at end of file
diff --git a/csharp/Neetcode.sln b/csharp/Neetcode.sln
new file mode 100644
index 000000000..fe0bba69a
--- /dev/null
+++ b/csharp/Neetcode.sln
@@ -0,0 +1,202 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.1.32228.430
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "1_ArrayAndHashing", "1-ArraysAndHashing\main\1_ArrayAndHashing.csproj", "{9DABB8E5-8DA4-41D3-A7FF-53ED73883764}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "1_ArrayAndHashingTest", "1-ArraysAndHashing\testCases\1_ArrayAndHashingTest.csproj", "{C6B86A92-B7C2-4A2D-84F7-3A00065BFAB0}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "2_TwoPointers", "2-TwoPointers\main\2_TwoPointers.csproj", "{796958DE-A0FE-4B58-9C74-15F616290A61}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "2_TwoPointersTest", "2-TwoPointers\testCases\2_TwoPointersTest.csproj", "{54F9EE8E-F622-44F8-9808-293AD5D989F7}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "3_SlidingWindow", "3-SlidingWindow\main\3_SlidingWindow.csproj", "{52A4C138-47CC-4389-BBF7-99666EF40871}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "3_SlidingWindowTest", "3-SlidingWindow\testCases\3_SlidingWindowTest.csproj", "{128A29BC-E47D-4472-8D42-82F10DF2F913}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "4_Stack", "4-Stack\main\4_Stack.csproj", "{FF57683A-C50C-40AC-9A3E-FAE4CA4F6E67}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "4_StackTest", "4-Stack\testCases\4_StackTest.csproj", "{96BD3BDB-B187-4FCC-AD9B-27B3BBD7B658}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "5_BinarySearch", "5-BinarySearch\main\5_BinarySearch.csproj", "{17A67069-564B-4BFC-A1B4-9C3D2DE81F12}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "5_BinarySearchTest", "5-BinarySearch\testCases\5_BinarySearchTest.csproj", "{86B4817A-6C76-485E-97AB-13FB8FD6AD59}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "6_LinkedList", "6_LinkedList\6_LinkedList.csproj", "{1C4134E9-206A-403E-A30B-8F7218DEE515}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "6_LinkedListTests", "6_LinkedListTests\6_LinkedListTests.csproj", "{AA71C362-B7FA-4438-AAE7-790D5AF7249A}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "7_Tree", "7_Tree\7_Tree.csproj", "{F2EB10AE-9392-429A-A45E-C78D607C3991}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "7_TreeTests", "7_TreeTests\7_TreeTests.csproj", "{45D76512-F232-44E1-BF3D-D3DB3535FF86}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "11_Graphs", "11-Graphs\main\11_Graphs.csproj", "{C37779A8-151F-45A4-BABE-6A5CDE1F2BC7}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "11_GraphTests", "11-Graphs\testCases\11_GraphTests.csproj", "{93381A4B-634C-47D9-8944-09BA53891B19}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "13_1DDynamicProgramming", "13-1DDynamicProgramming\main\13_1DDynamicProgramming.csproj", "{51F7C5F4-9C31-4902-9E7B-F83B8F9FC097}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "13_1DDynamicProgramming_Tests", "13-1DDynamicProgramming\testCases\13_1DDynamicProgramming_Tests.csproj", "{611ED41C-6E09-4D4F-8930-9673D2A8EAEA}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "14_2dDynamicProgramming", "14-2dDynamicProgramming\main\14_2dDynamicProgramming.csproj", "{B6D3F5A7-B63C-43C1-A75B-D3E23B00A3E7}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "14_2dDynamicProgramming_Tests", "14-2dDynamicProgramming\testCases\14_2dDynamicProgramming_Tests.csproj", "{5FCA9284-B1FA-4C5F-A261-73E24DB0BD2D}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "16_Intervals", "16-Intervals\main\16_Intervals.csproj", "{D5741B86-7FA1-4452-AA31-38C489A07705}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "17_MathAndGeometry", "17-MathAndGeometry\main\17_MathAndGeometry.csproj", "{8742E765-B743-4C7A-8D57-BB4D801FD173}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "17_MathAndGeometry_Tests", "17-MathAndGeometry\testCases\17_MathAndGeometry_Tests.csproj", "{5DB20F5D-9C42-4ED8-8549-003756A1A5BB}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "18_BitManipulation", "18_BitManipulation\18_BitManipulation.csproj", "{07B9E897-D8FE-4D78-AF5E-DC2792C9525D}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "18_BitManipulation_Tests", "18_BitManipulation_Tests\18_BitManipulation_Tests.csproj", "{E65DC80C-5671-46BA-95A6-77B8FB7456AD}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "16_Intervals_Tests", "16_Intervals_Tests\16_Intervals_Tests.csproj", "{58105687-8782-463B-BD1C-94E4AAC78261}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "11_BackTracking", "11_BackTracking\11_BackTracking.csproj", "{F2855C68-0733-4263-B924-747B776F6136}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "_11_BackTracking_Tests", "_11_BackTracking_Tests\_11_BackTracking_Tests.csproj", "{135B7EE6-04EA-4239-8905-3D1B498BB180}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AmazonQuestions", "AmazonQuestions", "{DDAC7B9E-9159-4527-B022-8D5DE7F2D3DF}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MakeArrayZeroBySubtractingEqualAmounts", "MakeArrayZeroBySubtractingEqualAmounts\MakeArrayZeroBySubtractingEqualAmounts.csproj", "{D0352AA7-C7FC-4EC6-99FF-E41B5A8CE3E3}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {9DABB8E5-8DA4-41D3-A7FF-53ED73883764}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9DABB8E5-8DA4-41D3-A7FF-53ED73883764}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9DABB8E5-8DA4-41D3-A7FF-53ED73883764}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9DABB8E5-8DA4-41D3-A7FF-53ED73883764}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C6B86A92-B7C2-4A2D-84F7-3A00065BFAB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C6B86A92-B7C2-4A2D-84F7-3A00065BFAB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C6B86A92-B7C2-4A2D-84F7-3A00065BFAB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C6B86A92-B7C2-4A2D-84F7-3A00065BFAB0}.Release|Any CPU.Build.0 = Release|Any CPU
+ {796958DE-A0FE-4B58-9C74-15F616290A61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {796958DE-A0FE-4B58-9C74-15F616290A61}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {796958DE-A0FE-4B58-9C74-15F616290A61}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {796958DE-A0FE-4B58-9C74-15F616290A61}.Release|Any CPU.Build.0 = Release|Any CPU
+ {54F9EE8E-F622-44F8-9808-293AD5D989F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {54F9EE8E-F622-44F8-9808-293AD5D989F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {54F9EE8E-F622-44F8-9808-293AD5D989F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {54F9EE8E-F622-44F8-9808-293AD5D989F7}.Release|Any CPU.Build.0 = Release|Any CPU
+ {52A4C138-47CC-4389-BBF7-99666EF40871}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {52A4C138-47CC-4389-BBF7-99666EF40871}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {52A4C138-47CC-4389-BBF7-99666EF40871}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {52A4C138-47CC-4389-BBF7-99666EF40871}.Release|Any CPU.Build.0 = Release|Any CPU
+ {128A29BC-E47D-4472-8D42-82F10DF2F913}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {128A29BC-E47D-4472-8D42-82F10DF2F913}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {128A29BC-E47D-4472-8D42-82F10DF2F913}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {128A29BC-E47D-4472-8D42-82F10DF2F913}.Release|Any CPU.Build.0 = Release|Any CPU
+ {FF57683A-C50C-40AC-9A3E-FAE4CA4F6E67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FF57683A-C50C-40AC-9A3E-FAE4CA4F6E67}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FF57683A-C50C-40AC-9A3E-FAE4CA4F6E67}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FF57683A-C50C-40AC-9A3E-FAE4CA4F6E67}.Release|Any CPU.Build.0 = Release|Any CPU
+ {96BD3BDB-B187-4FCC-AD9B-27B3BBD7B658}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {96BD3BDB-B187-4FCC-AD9B-27B3BBD7B658}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {96BD3BDB-B187-4FCC-AD9B-27B3BBD7B658}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {96BD3BDB-B187-4FCC-AD9B-27B3BBD7B658}.Release|Any CPU.Build.0 = Release|Any CPU
+ {17A67069-564B-4BFC-A1B4-9C3D2DE81F12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {17A67069-564B-4BFC-A1B4-9C3D2DE81F12}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {17A67069-564B-4BFC-A1B4-9C3D2DE81F12}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {17A67069-564B-4BFC-A1B4-9C3D2DE81F12}.Release|Any CPU.Build.0 = Release|Any CPU
+ {86B4817A-6C76-485E-97AB-13FB8FD6AD59}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {86B4817A-6C76-485E-97AB-13FB8FD6AD59}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {86B4817A-6C76-485E-97AB-13FB8FD6AD59}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {86B4817A-6C76-485E-97AB-13FB8FD6AD59}.Release|Any CPU.Build.0 = Release|Any CPU
+ {1C4134E9-206A-403E-A30B-8F7218DEE515}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {1C4134E9-206A-403E-A30B-8F7218DEE515}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {1C4134E9-206A-403E-A30B-8F7218DEE515}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {1C4134E9-206A-403E-A30B-8F7218DEE515}.Release|Any CPU.Build.0 = Release|Any CPU
+ {AA71C362-B7FA-4438-AAE7-790D5AF7249A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {AA71C362-B7FA-4438-AAE7-790D5AF7249A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {AA71C362-B7FA-4438-AAE7-790D5AF7249A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {AA71C362-B7FA-4438-AAE7-790D5AF7249A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F2EB10AE-9392-429A-A45E-C78D607C3991}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F2EB10AE-9392-429A-A45E-C78D607C3991}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F2EB10AE-9392-429A-A45E-C78D607C3991}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F2EB10AE-9392-429A-A45E-C78D607C3991}.Release|Any CPU.Build.0 = Release|Any CPU
+ {45D76512-F232-44E1-BF3D-D3DB3535FF86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {45D76512-F232-44E1-BF3D-D3DB3535FF86}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {45D76512-F232-44E1-BF3D-D3DB3535FF86}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {45D76512-F232-44E1-BF3D-D3DB3535FF86}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C37779A8-151F-45A4-BABE-6A5CDE1F2BC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C37779A8-151F-45A4-BABE-6A5CDE1F2BC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C37779A8-151F-45A4-BABE-6A5CDE1F2BC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C37779A8-151F-45A4-BABE-6A5CDE1F2BC7}.Release|Any CPU.Build.0 = Release|Any CPU
+ {494B9FFF-945D-470D-87B1-0180155B965D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {494B9FFF-945D-470D-87B1-0180155B965D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {494B9FFF-945D-470D-87B1-0180155B965D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {494B9FFF-945D-470D-87B1-0180155B965D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {93381A4B-634C-47D9-8944-09BA53891B19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {93381A4B-634C-47D9-8944-09BA53891B19}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {93381A4B-634C-47D9-8944-09BA53891B19}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {93381A4B-634C-47D9-8944-09BA53891B19}.Release|Any CPU.Build.0 = Release|Any CPU
+ {51F7C5F4-9C31-4902-9E7B-F83B8F9FC097}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {51F7C5F4-9C31-4902-9E7B-F83B8F9FC097}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {51F7C5F4-9C31-4902-9E7B-F83B8F9FC097}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {51F7C5F4-9C31-4902-9E7B-F83B8F9FC097}.Release|Any CPU.Build.0 = Release|Any CPU
+ {611ED41C-6E09-4D4F-8930-9673D2A8EAEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {611ED41C-6E09-4D4F-8930-9673D2A8EAEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {611ED41C-6E09-4D4F-8930-9673D2A8EAEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {611ED41C-6E09-4D4F-8930-9673D2A8EAEA}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B6D3F5A7-B63C-43C1-A75B-D3E23B00A3E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B6D3F5A7-B63C-43C1-A75B-D3E23B00A3E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B6D3F5A7-B63C-43C1-A75B-D3E23B00A3E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B6D3F5A7-B63C-43C1-A75B-D3E23B00A3E7}.Release|Any CPU.Build.0 = Release|Any CPU
+ {5FCA9284-B1FA-4C5F-A261-73E24DB0BD2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {5FCA9284-B1FA-4C5F-A261-73E24DB0BD2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5FCA9284-B1FA-4C5F-A261-73E24DB0BD2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {5FCA9284-B1FA-4C5F-A261-73E24DB0BD2D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D5741B86-7FA1-4452-AA31-38C489A07705}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D5741B86-7FA1-4452-AA31-38C489A07705}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D5741B86-7FA1-4452-AA31-38C489A07705}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D5741B86-7FA1-4452-AA31-38C489A07705}.Release|Any CPU.Build.0 = Release|Any CPU
+ {8742E765-B743-4C7A-8D57-BB4D801FD173}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {8742E765-B743-4C7A-8D57-BB4D801FD173}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {8742E765-B743-4C7A-8D57-BB4D801FD173}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {8742E765-B743-4C7A-8D57-BB4D801FD173}.Release|Any CPU.Build.0 = Release|Any CPU
+ {5DB20F5D-9C42-4ED8-8549-003756A1A5BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {5DB20F5D-9C42-4ED8-8549-003756A1A5BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5DB20F5D-9C42-4ED8-8549-003756A1A5BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {5DB20F5D-9C42-4ED8-8549-003756A1A5BB}.Release|Any CPU.Build.0 = Release|Any CPU
+ {07B9E897-D8FE-4D78-AF5E-DC2792C9525D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {07B9E897-D8FE-4D78-AF5E-DC2792C9525D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {07B9E897-D8FE-4D78-AF5E-DC2792C9525D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {07B9E897-D8FE-4D78-AF5E-DC2792C9525D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E65DC80C-5671-46BA-95A6-77B8FB7456AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E65DC80C-5671-46BA-95A6-77B8FB7456AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E65DC80C-5671-46BA-95A6-77B8FB7456AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E65DC80C-5671-46BA-95A6-77B8FB7456AD}.Release|Any CPU.Build.0 = Release|Any CPU
+ {58105687-8782-463B-BD1C-94E4AAC78261}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {58105687-8782-463B-BD1C-94E4AAC78261}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {58105687-8782-463B-BD1C-94E4AAC78261}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {58105687-8782-463B-BD1C-94E4AAC78261}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F2855C68-0733-4263-B924-747B776F6136}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F2855C68-0733-4263-B924-747B776F6136}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F2855C68-0733-4263-B924-747B776F6136}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F2855C68-0733-4263-B924-747B776F6136}.Release|Any CPU.Build.0 = Release|Any CPU
+ {135B7EE6-04EA-4239-8905-3D1B498BB180}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {135B7EE6-04EA-4239-8905-3D1B498BB180}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {135B7EE6-04EA-4239-8905-3D1B498BB180}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {135B7EE6-04EA-4239-8905-3D1B498BB180}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D0352AA7-C7FC-4EC6-99FF-E41B5A8CE3E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D0352AA7-C7FC-4EC6-99FF-E41B5A8CE3E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D0352AA7-C7FC-4EC6-99FF-E41B5A8CE3E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D0352AA7-C7FC-4EC6-99FF-E41B5A8CE3E3}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {A141F795-740A-43DD-9D6C-4619181B495F}
+ EndGlobalSection
+ GlobalSection(NestedProjects) = preSolution
+ {D0352AA7-C7FC-4EC6-99FF-E41B5A8CE3E3} = {DDAC7B9E-9159-4527-B022-8D5DE7F2D3DF}
+ EndGlobalSection
+EndGlobal
diff --git a/csharp/_11_BackTracking_Tests/L1863_SumOfAllSubsetsXorTotal_Tests.cs b/csharp/_11_BackTracking_Tests/L1863_SumOfAllSubsetsXorTotal_Tests.cs
new file mode 100644
index 000000000..200589b37
--- /dev/null
+++ b/csharp/_11_BackTracking_Tests/L1863_SumOfAllSubsetsXorTotal_Tests.cs
@@ -0,0 +1,21 @@
+using _11_BackTracking.L1863_SumOfAllSubsetsXorTotal;
+using FluentAssertions;
+using NUnit.Framework;
+
+namespace _11_BackTracking_Tests;
+
+public class L1863_SumOfAllSubsetsXorTotal_Tests
+{
+ [Test]
+ public void Example2_Test()
+ {
+ var nums = new int[] { 5, 1, 6 };
+
+ var solution = new Solution();
+ var result = solution.SubsetXORSum(nums);
+
+ result.Should().Be(28);
+ }
+
+
+}
\ No newline at end of file
diff --git a/csharp/_11_BackTracking_Tests/L39_CombinationSum_Tests.cs b/csharp/_11_BackTracking_Tests/L39_CombinationSum_Tests.cs
new file mode 100644
index 000000000..8f7345214
--- /dev/null
+++ b/csharp/_11_BackTracking_Tests/L39_CombinationSum_Tests.cs
@@ -0,0 +1,23 @@
+using _11_BackTracking.L39_CombinationSum;
+using FluentAssertions;
+using NUnit.Framework;
+
+namespace _11_BackTracking_Tests;
+
+public class L39_CombinationSum_Tests
+{
+ [Test]
+ public void Example1_Test()
+ {
+ int[] numbers = new[] { 2, 5, 6, 9 };
+ int target = 9;
+
+ var solution = new Solution();
+ var result = solution.CombinationSum(numbers, target);
+
+ result.Count.Should().Be(2);
+ result[0].Should().BeEquivalentTo(new List() { 2, 2, 5 });
+ result[1].Should().BeEquivalentTo(new List() { 9 });
+ }
+
+}
\ No newline at end of file
diff --git a/csharp/_11_BackTracking_Tests/L79_WordSearchTest.cs b/csharp/_11_BackTracking_Tests/L79_WordSearchTest.cs
new file mode 100644
index 000000000..26b1a1648
--- /dev/null
+++ b/csharp/_11_BackTracking_Tests/L79_WordSearchTest.cs
@@ -0,0 +1,44 @@
+using _11_BackTracking.WordSearch;
+using FluentAssertions;
+using NUnit.Framework;
+
+namespace _11_BackTracking_Tests;
+
+public class L79_WordSearchTest
+{
+ [Test]
+ public void TestExample1()
+ {
+ var board = new char[][]
+ {
+ ['A', 'B', 'C', 'D'],
+ ['S', 'A', 'A', 'T'],
+ ['A', 'C', 'A', 'E']
+ };
+
+ var solution = new Solution();
+ var result = solution.Exist(board, "CAT");
+
+ result.Should().BeTrue();
+ }
+
+ [Test]
+ public void TestExample2()
+ {
+ var board = new char[][]
+ {
+ ['A', 'B', 'C', 'D'],
+ ['S', 'A', 'A', 'T'],
+ ['A', 'C', 'A', 'E']
+ };
+
+ var solution = new Solution();
+ var result = solution.Exist(board, "BAT");
+
+ result.Should().BeFalse();
+
+ // we expect the iterations to be at least as big as r*c
+ var expectedIterationsWorstCase = (int)(board.Length * board[0].Length * Math.Pow(4, 3));
+ solution.Iterations.Should().BeLessOrEqualTo(expectedIterationsWorstCase);
+ }
+}
\ No newline at end of file
diff --git a/csharp/_11_BackTracking_Tests/PermutationTests.cs b/csharp/_11_BackTracking_Tests/PermutationTests.cs
new file mode 100644
index 000000000..82bb87e73
--- /dev/null
+++ b/csharp/_11_BackTracking_Tests/PermutationTests.cs
@@ -0,0 +1,46 @@
+using _11_BackTracking.Permutations;
+using FluentAssertions;
+using NUnit.Framework;
+
+namespace _11_BackTracking_Tests;
+
+public class PermutationTests
+{
+ [Test]
+ public void TestExample0()
+ {
+ var nums = new[] { 7, 5 };
+
+ var expectedResult = new List>()
+ {
+ new() { 5, 7 },
+ new() { 7, 5 }
+ };
+
+ var solution = new Solution();
+ var result = solution.Permute(nums);
+
+ result.Should().BeEquivalentTo(expectedResult);
+ }
+
+ [Test]
+ public void TestExample1()
+ {
+ var nums = new[] { 1, 2, 3 };
+
+ var expectedResult = new List>()
+ {
+ new() { 1, 2, 3 },
+ new() { 1, 3, 2 },
+ new() { 2, 1, 3 },
+ new() { 2, 3, 1 },
+ new() { 3, 1, 2 },
+ new() { 3, 2, 1 }
+ };
+
+ var solution = new Solution();
+ var result = solution.Permute(nums);
+
+ result.Should().BeEquivalentTo(expectedResult);
+ }
+}
\ No newline at end of file
diff --git a/csharp/_11_BackTracking_Tests/_11_BackTracking_Tests.csproj b/csharp/_11_BackTracking_Tests/_11_BackTracking_Tests.csproj
new file mode 100644
index 000000000..23a6093c6
--- /dev/null
+++ b/csharp/_11_BackTracking_Tests/_11_BackTracking_Tests.csproj
@@ -0,0 +1,19 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/csharp/readme.md b/csharp/readme.md
new file mode 100644
index 000000000..3e3442023
--- /dev/null
+++ b/csharp/readme.md
@@ -0,0 +1,9 @@
+# README
+
+1. On OSX test debugger won't work unless you add
+
+```xml
+false
+```
+
+in each *.csproj file.
\ No newline at end of file
diff --git a/go/blind75/arrayAndHashing/217_containsDuplicate.go b/go/blind75/arrayAndHashing/217_containsDuplicate.go
deleted file mode 100644
index f9c63f8fa..000000000
--- a/go/blind75/arrayAndHashing/217_containsDuplicate.go
+++ /dev/null
@@ -1,13 +0,0 @@
-package arrayAndHashing
-
-func containsDuplicate(nums []int) bool {
- freqMap := make(map[int]int)
-
- for i := 0; i < len(nums); i++ {
- if _, ok := freqMap[nums[i]]; ok {
- return true
- }
- freqMap[nums[i]] += 1
- }
- return false
-}
diff --git a/java/1-Two-Sum.java b/java/1-Two-Sum.java
deleted file mode 100644
index 2f420c89f..000000000
--- a/java/1-Two-Sum.java
+++ /dev/null
@@ -1,18 +0,0 @@
-class Solution {
- public int[] twoSum(int[] nums, int target) {
- HashMap prevMap = new HashMap<>();
-
- for (int i = 0; i < nums.length; i++) {
- int num = nums[i];
- int diff = target - num;
-
- if (prevMap.containsKey(nums[i])) {
- return new int[]{prevMap.get(num), i};
- }
-
- prevMap.put(target - num, i);
- }
-
- return new int[]{};
- }
-}
\ No newline at end of file
diff --git a/java/11-Container-With-Most-Water.java b/java/11-Container-With-Most-Water.java
deleted file mode 100644
index 1742d11c2..000000000
--- a/java/11-Container-With-Most-Water.java
+++ /dev/null
@@ -1,18 +0,0 @@
-class Solution {
- public int maxArea(int[] height) {
- int left = 0;
- int right = height.length - 1;
- int res = 0;
- while (left < right) {
- int containerLength = right - left;
- int area = containerLength * Math.min(height[left], height[right]);
- res = Math.max(res, area);
- if (height[left] < height[right]) {
- left++;
- } else {
- right--;
- }
- }
- return res;
- }
-}
\ No newline at end of file
diff --git a/java/125-Valid-Palindrome.java b/java/125-Valid-Palindrome.java
deleted file mode 100644
index 5742f698c..000000000
--- a/java/125-Valid-Palindrome.java
+++ /dev/null
@@ -1,9 +0,0 @@
-public boolean isPalindrome(String s) {
- StringBuilder content = new StringBuilder();
- for(int i = 0; i < s.length(); i++)
- if(Character.isLetterOrDigit(s.charAt(i)))
- content.append(s.charAt(i));
- content = new StringBuilder(content.toString().replace(" ", "").toLowerCase());
- String value = content.toString();
- return value.equals(content.reverse().toString());
- }
diff --git a/java/131-Palindrome-Partitioning.java b/java/131-Palindrome-Partitioning.java
deleted file mode 100644
index d4c13c802..000000000
--- a/java/131-Palindrome-Partitioning.java
+++ /dev/null
@@ -1,26 +0,0 @@
-public class Solution {
- public List> partition(String s) {
- List> res = new ArrayList>();
- if (s.equals("")) {
- res.add(new ArrayList());
- return res;
- }
- for (int i = 0; i < s.length(); i++) {
- if (isPalindrome(s, i + 1)) {
- for (List list : partition(s.substring(i+1))) {
- list.add(0, s.substring(0, i + 1));
- res.add(list);
- }
- }
- }
- return res;
- }
-
- public boolean isPalindrome(String s, int n) {
- for (int i = 0; i < n / 2; i++) {
- if (s.charAt(i) != s.charAt(n - i - 1))
- return false;
- }
- return true;
- }
-}
\ No newline at end of file
diff --git a/java/15-3Sum.java b/java/15-3Sum.java
deleted file mode 100644
index e0329ec78..000000000
--- a/java/15-3Sum.java
+++ /dev/null
@@ -1,39 +0,0 @@
-class Solution {
-//2 pointers
- public List> threeSum(int[] nums) {
- Arrays.sort(nums);
- LinkedList> sol = new LinkedList>();
-
- for (int i = 0; i < nums.length - 2; i++) {
- if (i == 0 || (i > 0 && nums[i] != nums[i - 1])) {
- int target = 0 - nums[i];
- int left = i + 1;
- int right = nums.length - 1;
-
- while (left < right) {
- if (nums[left] + nums[right] == target) {
- ArrayList miniSol = new ArrayList<>();
- miniSol.add(nums[i]);
- miniSol.add(nums[left]);
- miniSol.add(nums[right]);
- sol.add(miniSol);
- while (left < right && nums[left] == nums[left + 1]) {
- left++;
- }
- while (left < right && nums[right] == nums[right - 1]) {
- right--;
- }
- left++;
- right--;
- } else if (nums[left] + nums[right] > target) {
- right--;
- } else {
- left++;
- }
- }
- }
- }
-
- return sol;
- }
-}
diff --git a/java/167-Two-Sum-II.java b/java/167-Two-Sum-II.java
deleted file mode 100644
index 482802882..000000000
--- a/java/167-Two-Sum-II.java
+++ /dev/null
@@ -1,24 +0,0 @@
-class Solution {
- public int[] twoSum(int[] numbers, int target) {
- int a_pointer = 0;
- int b_pointer = numbers.length - 1;
- int num_a, num_b;
-
- while(a_pointer < b_pointer) {
- num_a = numbers[a_pointer];
- num_b = numbers[b_pointer];
-
- if(num_a + num_b == target) break;
-
- if(num_a + num_b < target) {
- a_pointer++;
- continue;
- }
-
- b_pointer--;
-
- }
-
- return new int[]{a_pointer + 1, b_pointer + 1};
- }
-}
diff --git a/java/208-Implement-Trie-Prefix-Tree.java b/java/208-Implement-Trie-Prefix-Tree.java
deleted file mode 100644
index 1f68fb540..000000000
--- a/java/208-Implement-Trie-Prefix-Tree.java
+++ /dev/null
@@ -1,54 +0,0 @@
-class Trie {
- Node root;
-
- public Trie() {
- root = new Node('\0'); //dummy node
- }
-
- public void insert(String word) {
- Node curr = root;
- for (char x : word.toCharArray()) {
- if (curr.children[x - 'a'] == null) {
- curr.children[x - 'a'] = new Node(x);
- }
- curr = curr.children[x - 'a'];
- }
- curr.isWord = true;
- }
-
- public boolean search(String word) {
- Node res = getLast(word);
- return (res != null && res.isWord);
- }
-
- //helper method
- public Node getLast(String word) {
- Node curr = root;
- for (char x : word.toCharArray()) {
- if (curr.children[x - 'a'] == null) {
- return null;
- }
-
- curr = curr.children[x - 'a'];
- }
- return curr;
- }
-
- public boolean startsWith(String prefix) {
- Node res = getLast(prefix);
- if (res == null) return false;
- return true;
- }
-
- class Node {
- private char value;
- private boolean isWord;
- private Node[] children;
-
- public Node(char val) {
- this.value = val;
- this.isWord = false;
- this.children = new Node[26];
- }
- }
-}
diff --git a/java/21-Merge-Two-Sorted-Lists.java b/java/21-Merge-Two-Sorted-Lists.java
deleted file mode 100644
index 23c6bca73..000000000
--- a/java/21-Merge-Two-Sorted-Lists.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * Definition for singly-linked list.
- * public class ListNode {
- * int val;
- * ListNode next;
- * ListNode() {}
- * ListNode(int val) { this.val = val; }
- * ListNode(int val, ListNode next) { this.val = val; this.next = next; }
- * }
- */
-class Solution {
- public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
- final ListNode root = new ListNode();
- ListNode prev = root;
- while (list1 != null && list2 != null) {
- if(list1.val < list2.val) {
-
-
- prev.next = list1;
- list1 = list1.next;
- } else {
- prev.next = list2;
- list2 = list2.next;
- }
- prev = prev.next;
- }
- prev.next = list1 != null ? list1 : list2;
- return root.next;
- }
-}
-
-// Solution using Recursion
-/**
- * Definition for singly-linked list.
- * public class ListNode {
- * int val;
- * ListNode next;
- * ListNode() {}
- * ListNode(int val) { this.val = val; }
- * ListNode(int val, ListNode next) { this.val = val; this.next = next; }
- * }
- */
-class Solution {
- public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
- ListNode head = new ListNode(0);
-
- if(list1 == null && list2 == null) return null;
- if(list1 == null) return list2;
- if(list2 == null) return list1;
-
- if(list1.val > list2.val) {
- head = list2;
- list2 = list2.next;
- } else {
- head = list1;
- list1 = list1.next;
- }
- head.next = mergeTwoLists(list1, list2);
- return head;
- }
-}
diff --git a/java/217-Contains-Duplicate.java b/java/217-Contains-Duplicate.java
deleted file mode 100644
index 9c59be683..000000000
--- a/java/217-Contains-Duplicate.java
+++ /dev/null
@@ -1,11 +0,0 @@
-class Solution {
- public boolean containsDuplicate(int[] nums) {
- Set numbers = new HashSet();
- for (int num : nums) {
- if (numbers.contains(num)) return true;
- numbers.add(num);
- }
-
- return false;
- }
-}
\ No newline at end of file
diff --git a/java/242-Valid-Anagram.java b/java/242-Valid-Anagram.java
deleted file mode 100644
index a5edb5b04..000000000
--- a/java/242-Valid-Anagram.java
+++ /dev/null
@@ -1,20 +0,0 @@
-class Solution {
- public boolean isAnagram(String s, String t) {
-
- if(s.length() != t.length()) return false;
- if(s.equals(t)) return true;
-
- Map sMap = new HashMap<>();
- Map tMap = new HashMap<>();
-
- for(int i = 0; i < s.length(); i++) {
- sMap.merge(s.charAt(i), 1, Integer::sum);
- tMap.merge(t.charAt(i), 1, Integer::sum);
- }
-
- for(Character c : sMap.keySet()) {
- if(!sMap.get(c).equals(tMap.get(c))) return false;
- }
- return true;
- }
-}
diff --git a/java/268-Missing-Number.java b/java/268-Missing-Number.java
deleted file mode 100644
index 2f0bd92ae..000000000
--- a/java/268-Missing-Number.java
+++ /dev/null
@@ -1,10 +0,0 @@
-class Solution {
- public int missingNumber(int[] nums) {
- int sum = 0;
- int total = nums.length * (nums.length+1)/2;
- for(int i = 0; i < nums.length; i++){
- sum += nums[i];
- }
- return total - sum;
- }
-}
diff --git a/java/271-Encode-and-Decode-Strings.java b/java/271-Encode-and-Decode-Strings.java
deleted file mode 100644
index 3651b3f14..000000000
--- a/java/271-Encode-and-Decode-Strings.java
+++ /dev/null
@@ -1,33 +0,0 @@
-public class Solution {
-
- public String encode(List strs) {
- StringBuilder encodedString = new StringBuilder();
- for(String str: strs){
- int length = str.length();
- encodedString.append(length+"#");
- encodedString.append(str);
- }
- return encodedString.toString();
- }
-
- public List decode(String str) {
- List decodedStrings = new ArrayList();
- for(int i =0;i h1 = new HashSet();
-
- for(int i=0; i < 9; i++){
- for(int j=0; j< 9; j++){
- if(board[i][j] != '.'){
-
- //Check whether HashSet contains duplicate elements in row and column
- if(h1.contains("row" + i + board[i][j]) || h1.contains("col" + j + board[i][j]) ){
- return false;
- }
- h1.add("row" + i + board[i][j]);
- h1.add("col" + j + board[i][j]);
-
-
- //Check whether Box contains duplicate elements in it
- if(h1.contains("box"+ (i/3)*3 + j/3 + board[i][j])){
- return false;
- }
- h1.add("box"+ (i/3)*3 + j/3 + board[i][j]);
- }
- }
- }
-
-
- return true;
- }
-}
diff --git a/java/371-Sum-of-Two-Integers.java b/java/371-Sum-of-Two-Integers.java
deleted file mode 100644
index ff641469f..000000000
--- a/java/371-Sum-of-Two-Integers.java
+++ /dev/null
@@ -1,10 +0,0 @@
-class Solution {
- public int getSum(int a, int b) {
- while (b != 0) {
- int tmp = (a & b) << 1;
- a = (a ^ b);
- b = tmp;
- }
- return a;
- }
-}
diff --git a/java/42-Trapping-Rain-Water.java b/java/42-Trapping-Rain-Water.java
deleted file mode 100644
index b1a32ddab..000000000
--- a/java/42-Trapping-Rain-Water.java
+++ /dev/null
@@ -1,22 +0,0 @@
-class Solution {
- public int trap(int[] heights) {
- int left[]=new int[heights.length],right[]=new int[heights.length],max=heights[0],c=0;
-
- for(int i=0;i=0;i--){
- right[i]=Math.max(heights[i],max);
- max=right[i];
- }
- System.out.println(Arrays.toString(right));
- for(int i=0;i Integer.compare(arr1[0], arr2[0]));
-
- int[] intervalFirst = intervals[0];
-
- for(int i = 1; i < intervals.length; i++){
- if(firstIntervalwithinSecond(intervalFirst, intervals[i])){
- //mark first interval to be removed
- intervalsRemoved++;
- // determine which interval to remove
- //remove the interval that ends last
- if(intervalFirst[1] > intervals[i][1]){
- intervalFirst = intervals[i];
- }
- } else {
- intervalFirst = intervals[i];
- }
- }
- return intervalsRemoved;
- }
-
- public boolean firstIntervalwithinSecond(int[] intervalFirst, int[] intervalSecond){
- return intervalSecond[0] < intervalFirst[1];
- }
-}
diff --git a/java/48-Rotate-Image.java b/java/48-Rotate-Image.java
deleted file mode 100644
index d53b84f19..000000000
--- a/java/48-Rotate-Image.java
+++ /dev/null
@@ -1,34 +0,0 @@
-// Do note that this is for a sqaure matrix (NxN)
-// The process is to first transpose the matrix and then reverse it
-// Taking the first example: [[1,2,3],[4,5,6],[7,8,9]]
-// After Transpose: [[1,4,7],[2,5,8],[3,6,9]]
-// After Reversal: [[7,4,1],[8,5,2],[9,6,3]]
-
-class Solution {
- public void rotate(int[][] matrix) {
- int N = matrix.length;
-
- transpose(matrix, N);
- reverse(matrix, N);
- }
-
- void transpose(int[][] matrix, int n) {
- for (int i = 0; i < n; i++) {
- for (int j = i + 1; j < n; j++) {
- int temp = matrix[j][i];
- matrix[j][i] = matrix[i][j];
- matrix[i][j] = temp;
- }
- }
- }
-
- void reverse(int[][] matrix, int n) {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n / 2; j++) {
- int temp = matrix[i][j];
- matrix[i][j] = matrix[i][n - 1 - j];
- matrix[i][n - 1 - j] = temp;
- }
- }
- }
-}
diff --git a/java/49-Group-Anagrams.java b/java/49-Group-Anagrams.java
deleted file mode 100644
index de03e7ac2..000000000
--- a/java/49-Group-Anagrams.java
+++ /dev/null
@@ -1,20 +0,0 @@
-class Solution {
- public List> groupAnagrams(String[] strs) {
- List> res = new ArrayList<>();
- if(strs.length==0) return res;
- HashMap> map = new HashMap();
- for(String s: strs){
- char[] hash = new char[26];
- for(char c: s.toCharArray()){
- hash[c-'a']++;
- }
- String str=new String(hash);
- if(map.get(str)==null){
- map.put(str, new ArrayList<>());
- }
- map.get(str).add(s);
- }
- res.addAll(map.values());
- return res;
- }
-}
\ No newline at end of file
diff --git a/java/53-Maximum-Subarray.java b/java/53-Maximum-Subarray.java
deleted file mode 100644
index 9a59bfe3a..000000000
--- a/java/53-Maximum-Subarray.java
+++ /dev/null
@@ -1,18 +0,0 @@
-class Solution {
- public int maxSubArray(int[] nums) {
- if(nums.length == 1) return nums[0];
-
- int sum = 0;
- int max = Integer.MIN_VALUE;
-
- for(int n : nums){
- sum += n;
- max = Math.max(max, sum);
-
- if(sum < 0){
- sum = 0;
- }
- }
- return max;
- }
-}
diff --git a/java/543-Diameter-of-Binary-Tree.java b/java/543-Diameter-of-Binary-Tree.java
deleted file mode 100644
index 814102639..000000000
--- a/java/543-Diameter-of-Binary-Tree.java
+++ /dev/null
@@ -1,32 +0,0 @@
-class Solution {
- private static int treeDiameter = 0;
-
- public int diameterOfBinaryTree(TreeNode root) {
- calculateHeight(root);
- return treeDiameter-1;
- }
-
- private static int calculateHeight(TreeNode currentNode) {
- if (currentNode == null)
- return 0;
-
- int leftTreeHeight = calculateHeight(currentNode.left);
- int rightTreeHeight = calculateHeight(currentNode.right);
-
- // if the current node doesn't have a left or right subtree, we can't have
- // a path passing through it, since we need a leaf node on each side
- if (leftTreeHeight != 0 && rightTreeHeight != 0) {
-
- // diameter at the current node will be equal to the height of left subtree +
- // the height of right sub-trees + '1' for the current node
- int diameter = leftTreeHeight + rightTreeHeight + 1;
-
- // update the global tree diameter
- treeDiameter = Math.max(treeDiameter, diameter);
- }
-
- // height of the current node will be equal to the maximum of the heights of
- // left or right subtrees plus '1' for the current node
- return Math.max(leftTreeHeight, rightTreeHeight) + 1;
- }
-}
diff --git a/java/55-Jump-Game.java b/java/55-Jump-Game.java
deleted file mode 100644
index e8475fa87..000000000
--- a/java/55-Jump-Game.java
+++ /dev/null
@@ -1,12 +0,0 @@
-class Solution {
- public boolean canJump(int[] nums) {
- int goal = nums.length-1;
- for (int i = nums.length-2; i >= 0; i--) {
- if (nums[i] + i >= goal) {
- goal = i;
- }
- }
- return goal == 0;
- }
-}
-
diff --git a/java/704-Binary-Search.java b/java/704-Binary-Search.java
deleted file mode 100644
index 19d2a60c1..000000000
--- a/java/704-Binary-Search.java
+++ /dev/null
@@ -1,16 +0,0 @@
-class Solution {
- public int search(int[] nums, int target) {
-
- int i = 0;
- int j = nums.length-1;
-
- while(i<=j){
- int mid = (i+j)/2;
-
- if(nums[mid] == target) return mid;
- else if(nums[mid] map = new HashMap<>();
-
- for (char x : t.toCharArray()) {
- map.put(x, map.getOrDefault(x, 0) + 1);
- }
-
- int matched = 0;
- int start = 0;
- int minLen = s.length() + 1;
- int subStr = 0;
- for (int endWindow = 0; endWindow < s.length(); endWindow++) {
- char right = s.charAt(endWindow);
- if (map.containsKey(right)) {
- map.put(right, map.get(right) - 1);
- if (map.get(right) == 0) matched++;
- }
-
- while (matched == map.size()) {
- if (minLen > endWindow - start + 1) {
- minLen = endWindow - start + 1;
- subStr = start;
- }
- char deleted = s.charAt(start++);
- if (map.containsKey(deleted)) {
- if (map.get(deleted) == 0) matched--;
- map.put(deleted, map.get(deleted) + 1);
- }
- }
- }
- return minLen > s.length() ? "" : s.substring(subStr, subStr + minLen);
- }
-}
diff --git a/java/98-Validate-Binary-Search-Tree.java b/java/98-Validate-Binary-Search-Tree.java
deleted file mode 100644
index ba296426a..000000000
--- a/java/98-Validate-Binary-Search-Tree.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * Definition for a binary tree node.
- * public class TreeNode {
- * int val;
- * TreeNode left;
- * TreeNode right;
- * TreeNode() {}
- * TreeNode(int val) { this.val = val; }
- * TreeNode(int val, TreeNode left, TreeNode right) {
- * this.val = val;
- * this.left = left;
- * this.right = right;
- * }
- * }
- */
-class Solution {
- public boolean isValidBST(TreeNode root) {
- if (root == null) return true;
- return dfs(root, null, null);
- }
-
- private boolean dfs(TreeNode root, Integer min, Integer max) {
- if (root == null) return true;
-
- if ((min != null && root.val <= min) || max != null && root.val >= max) {
- return false;
- }
-
- return dfs(root.left, min, root.val) && dfs(root.right, root.val, max);
-
- }
-}
-
diff --git a/javascript/1-Two-Sum.js b/javascript/1-Two-Sum.js
deleted file mode 100644
index 56e9b10fe..000000000
--- a/javascript/1-Two-Sum.js
+++ /dev/null
@@ -1,15 +0,0 @@
-/**
- * @param {number[]} nums
- * @param {number} target
- * @return {number[]}
- */
-var twoSum = function(nums, target) {
- let map = {};
- for (let i = 0; i < nums.length; i++) {
- if (target - nums[i] in map) {
- return [map[target-nums[i]], i];
- } else {
- map[nums[i]] = i;
- }
- }
-};
diff --git a/javascript/100-Same-Tree.js b/javascript/100-Same-Tree.js
deleted file mode 100644
index 25db45766..000000000
--- a/javascript/100-Same-Tree.js
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- * Definition for a binary tree node.
- * function TreeNode(val, left, right) {
- * this.val = (val===undefined ? 0 : val)
- * this.left = (left===undefined ? null : left)
- * this.right = (right===undefined ? null : right)
- * }
- */
-/**
- * @param {TreeNode} p
- * @param {TreeNode} q
- * @return {boolean}
- */
-var isSameTree = function(p, q) {
- if (!p && !q) return true;
- if (!p || !q || p.val !== q.val) return false;
- return isSameTree(p.right,q.right) && isSameTree(p.left, q.left);
-};
diff --git a/javascript/104-Maximum-Depth-of-Binary-Tree.js b/javascript/104-Maximum-Depth-of-Binary-Tree.js
deleted file mode 100644
index 7cf81388a..000000000
--- a/javascript/104-Maximum-Depth-of-Binary-Tree.js
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * Definition for a binary tree node.
- * function TreeNode(val, left, right) {
- * this.val = (val===undefined ? 0 : val)
- * this.left = (left===undefined ? null : left)
- * this.right = (right===undefined ? null : right)
- * }
- */
-/**
- * @param {TreeNode} root
- * @return {number}
- */
-var maxDepth = (root) => {
- let maxDepth = 0;
- let DFS = (node, depth) => {
- if (!node) return maxDepth;
- if (depth > maxDepth) maxDepth = depth;
- DFS(node.right, depth + 1);
- DFS(node.left, depth + 1);
- }
- DFS(root, 1);
- return maxDepth;
-};
diff --git a/javascript/11-Container-With-Most-Water.js b/javascript/11-Container-With-Most-Water.js
deleted file mode 100644
index 11b35406d..000000000
--- a/javascript/11-Container-With-Most-Water.js
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * @param {number[]} height
- * @return {number}
- */
-var maxArea = function(height) {
- let max = 0;
- let i = 0;
- let j = height.length - 1;
-
- while (i < j) {
- curr = (j - i) * Math.min(height[i], height[j]);
- max = Math.max(curr, max);
- if (height[i] > height[j]) {
- j--;
- } else {
- i++;
- }
- }
- return max;
-};
diff --git a/javascript/110-Balanced-Binary-Tree.js b/javascript/110-Balanced-Binary-Tree.js
deleted file mode 100644
index 0f492c0c1..000000000
--- a/javascript/110-Balanced-Binary-Tree.js
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * Definition for a binary tree node.
- * function TreeNode(val, left, right) {
- * this.val = (val===undefined ? 0 : val)
- * this.left = (left===undefined ? null : left)
- * this.right = (right===undefined ? null : right)
- * }
- */
-/**
- * @param {TreeNode} root
- * @return {boolean}
- */
- var isBalanced = function (root) {
- if (!root) return true
- const left = findHeight(root.left)
- const right = findHeight(root.right)
- return Math.abs(left - right) <= 1 && isBalanced(root.left) && isBalanced(root.right)
-};
-
-function findHeight(node) {
- if (node == null) return 0;
- return 1 + Math.max(this.findHeight(node.left), this.findHeight(node.right));
-}
-
-// Runtime: 78 ms, faster than 90.43% of JavaScript online submissions for Balanced Binary Tree.
-// Memory Usage: 47.1 MB, less than 32.41% of JavaScript online submissions for Balanced Binary Tree.
\ No newline at end of file
diff --git a/javascript/1143-Longest-Common-Subsequence.js b/javascript/1143-Longest-Common-Subsequence.js
deleted file mode 100644
index 756db3824..000000000
--- a/javascript/1143-Longest-Common-Subsequence.js
+++ /dev/null
@@ -1,17 +0,0 @@
-var longestCommonSubsequence = function (text1, text2) {
- let m = text1.length;
- let n = text2.length;
-
- let table = new Array(m + 1).fill().map(() => new Array(n + 1).fill(0));
-
- for (let i = 1; i <= m; i++) {
- for (let j = 1; j <= n; j++) {
- if (text1.charAt(i - 1) !== text2.charAt(j - 1)) {
- table[i][j] = Math.max(table[i - 1][j], table[i][j - 1]);
- } else {
- table[i][j] = table[i - 1][j - 1] + 1;
- }
- }
- }
- return table[m][n];
-};
\ No newline at end of file
diff --git a/javascript/121-Best-Time-to-Buy-and-Sell-Stock.js b/javascript/121-Best-Time-to-Buy-and-Sell-Stock.js
deleted file mode 100644
index c8436d470..000000000
--- a/javascript/121-Best-Time-to-Buy-and-Sell-Stock.js
+++ /dev/null
@@ -1,16 +0,0 @@
-/**
- * @param {number[]} prices
- * @return {number}
- */
-var maxProfit = function(prices) {
- let buy = prices[0];
- let profit = 0;
- for (let i = 0; i < prices.length; i++) {
- if (prices[i] < buy) {
- buy = prices[i];
- } else {
- profit = Math.max(prices[i] - buy, profit);
- }
- }
- return profit;
-};
diff --git a/javascript/125-ValidPalindrome.js b/javascript/125-ValidPalindrome.js
deleted file mode 100644
index 8067737e4..000000000
--- a/javascript/125-ValidPalindrome.js
+++ /dev/null
@@ -1,30 +0,0 @@
-class isValidPalindrome {
- constructor(string){
- this.string=string;
- }
- isPalindrome(string){
- let left =0;
- let right=string.length-1;
- while(leftleft && this.isAlphaNumeric(string[right])){
- right--
- }
- if(string[left].toLowerCase()!=string[right].toLowerCase()) {
- return false;
- }
- left++
- right--
- }
- return true
- }
-
- isAlphaNumeric(c){
- return ('A'.charCodeAt(0) <= c.charCodeAt(0) <='Z'.charCodeAt(0) ||
- 'a'.charCodeAt(0) <= c.charCodeAt(0) <='z'.charCodeAt(0) ||
- '0'.charCodeAt(0) <= c.charCodeAt(0) <='9'.charCodeAt(0))
- }
-
-}
\ No newline at end of file
diff --git a/javascript/13-Roman-to-Integer.js b/javascript/13-Roman-to-Integer.js
deleted file mode 100644
index 993d6738b..000000000
--- a/javascript/13-Roman-to-Integer.js
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * @param {string} s
- * @return {number}
- */
-var romanToInt = function (s) {
- let romans = {
- I: 1,
- V: 5,
- X: 10,
- L: 50,
- C: 100,
- D: 500,
- M: 1000,
- };
-
- let arr = s.split("");
-
- let sum = 0;
-
- for (let i = arr.length - 1; i >= 0; i--) {
- // IV : 4
- if (romans[arr[i]] === romans["V"]) {
- if (romans[arr[i - 1]] === romans["I"]) {
- sum -= 1 * 2;
- }
- }
- // IX : 4
- if (romans[arr[i]] === romans["X"]) {
- if (romans[arr[i - 1]] === romans["I"]) {
- sum -= 1 * 2;
- }
- }
- // XL : 40
- if (romans[arr[i]] === romans["L"]) {
- if (romans[arr[i - 1]] === romans["X"]) {
- sum -= 10 * 2;
- }
- }
- // XC : 90
- if (romans[arr[i]] === romans["C"]) {
- if (romans[arr[i - 1]] === romans["X"]) {
- sum -= 10 * 2;
- }
- }
- // CD : 400
- if (romans[arr[i]] === romans["D"]) {
- if (romans[arr[i - 1]] === romans["C"]) {
- sum -= 100 * 2;
- }
- }
- // CM : 900
- if (romans[arr[i]] === romans["M"]) {
- if (romans[arr[i - 1]] === romans["C"]) {
- sum -= 100 * 2;
- }
- }
-
- sum += romans[arr[i]];
- }
-
- return sum;
-};
-
-// Runtime: 148 ms, faster than 80.16% of JavaScript online submissions for Roman to Integer.
-// Memory Usage: 47.5 MB, less than 18.15% of JavaScript online submissions for Roman to Integer.
diff --git a/javascript/136-Single-Number.js b/javascript/136-Single-Number.js
deleted file mode 100644
index fddbfaf06..000000000
--- a/javascript/136-Single-Number.js
+++ /dev/null
@@ -1,11 +0,0 @@
-/**
- * @param {number[]} nums
- * @return {number}
- */
-var singleNumber = function (nums) {
- let xor_final = 0;
- for (num of nums) {
- xor_final = xor_final ^ num
- }
- return xor_final
-};
diff --git a/javascript/141-Linked-List-Cycle.js b/javascript/141-Linked-List-Cycle.js
deleted file mode 100644
index d79850599..000000000
--- a/javascript/141-Linked-List-Cycle.js
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * Definition for singly-linked list.
- * function ListNode(val) {
- * this.val = val;
- * this.next = null;
- * }
- */
-
-/**
- * @param {ListNode} head
- * @return {boolean}
- */
-var hasCycle = function(head) {
- let set = new Set();
- while (head) {
- if (set.has(head)) {
- return true;
- } else {
- set.add(head);
- head = head.next;
- }
- }
-
- return false;
-};
diff --git a/javascript/143-Reorder-List.js b/javascript/143-Reorder-List.js
deleted file mode 100644
index dbc5468a0..000000000
--- a/javascript/143-Reorder-List.js
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * Definition for singly-linked list.
- * function ListNode(val, next) {
- * this.val = (val===undefined ? 0 : val)
- * this.next = (next===undefined ? null : next)
- * }
- */
-/**
- * @param {ListNode} head
- * @return {void} Do not return anything, modify head in-place instead.
- */
-var reorderList = function(head) {
- if (!head) { return };
-
- let slow = head;
- let fast = head;
-
-
- // finding the middle of the linked list using 2 pters
- while (fast && fast.next) {
- slow = slow.next;
- fast = fast.next.next;
- }
-
- // reverse the second part of the list starting at slow
- let prev = null
- let curr = slow;
- while (curr) {
- let next = curr.next;
- curr.next = prev;
- prev = curr;
- curr = next;
- } // here prev is the head
-
- // merge two sorted lists (first one starts at head, second at prev)
- let first = head;
- let second = prev;
-
- while(second.next) {
- temp = first.next;
- first.next = second;
- first = temp;
-
- temp = second.next;
- second.next = first;
- second = temp;
- }
-
-
-};
diff --git a/javascript/15-3Sum.js b/javascript/15-3Sum.js
deleted file mode 100644
index db5aaffcb..000000000
--- a/javascript/15-3Sum.js
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * @param {number[]} nums
- * @return {number[][]}
- */
-var threeSum = function(nums) {
- let res = [];
- let left = 0;
- let right = nums.length - 1;
- nums.sort((a,b) => { return a - b })
-
- for (let i = 0; i < nums.length - 1; i++) {
- if (nums[i] > 0) return res;
- if (nums[i] === nums[i - 1]) continue;
-
- left = i + 1;
- right = nums.length - 1;
- let temp = 0;
-
- while (left < right) {
- temp = nums[left] + nums[right] + nums[i];
- if (temp === 0) {
- res.push([nums[i], nums[left], nums[right]]);
- left++;
- right--;
-
- while(nums[left] == nums[left - 1]) { left++ };
-
- while (nums[right] == nums[right - 1]) { right-- };
-
- } else if (temp > 0) { right-- }
- else if (temp < 0) { left++ }
- }
- }
- return res;
-};
diff --git a/javascript/152-Maximum-Product-Subarray.js b/javascript/152-Maximum-Product-Subarray.js
deleted file mode 100644
index 64519e177..000000000
--- a/javascript/152-Maximum-Product-Subarray.js
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * @param {number[]} nums
- * @return {number}
- */
-var maxProduct = function(nums) {
- let result = nums[0];
- let prevMax = nums[0];
- let prevMin = nums[0];
- for(let i = 1; i < nums.length; i++) {
- currMax = Math.max(nums[i], prevMax * nums[i], prevMin * nums[i]);
- currMin = Math.min(nums[i], prevMax * nums[i], prevMin * nums[i]);
-
- prevMax = currMax;
- prevMin = currMin;
-
- result = Math.max(currMax, result);
- }
- return result;
-
-};
diff --git a/javascript/153-Find-Minimum-in-Rotated-Sorted-Array.js b/javascript/153-Find-Minimum-in-Rotated-Sorted-Array.js
deleted file mode 100644
index 2c28650e2..000000000
--- a/javascript/153-Find-Minimum-in-Rotated-Sorted-Array.js
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
- * @param {number[]} nums
- * @return {number}
- */
-var findMin = function(nums) {
- let left = 0;
- let right = nums.length - 1;
- while (right > left) {
- let mid = Math.floor((right + left) / 2);
- if (nums[mid] > nums[right]) {
- left = mid + 1;
- } else {
- right = mid;
- }
- }
- return nums[left];
-};
diff --git a/javascript/167-Two-Sum-II.js b/javascript/167-Two-Sum-II.js
deleted file mode 100644
index 57fece92d..000000000
--- a/javascript/167-Two-Sum-II.js
+++ /dev/null
@@ -1,16 +0,0 @@
-/**
- * @param {number[]} numbers
- * @param {number} target
- * @return {number[]}
- */
- var twoSum = function(numbers, target) {
- let start = 0;
- let end = numbers.length -1;
- while (start < end) {
- let currSum = numbers[start] + numbers[end];
- if (currSum > target) end--;
- else if (currSum < target) start++;
- else return [start +1, end +1];
- };
- return [];
-};
diff --git a/javascript/19-Remove-Nth-Node-From-End-of-List.js b/javascript/19-Remove-Nth-Node-From-End-of-List.js
deleted file mode 100644
index e52e76058..000000000
--- a/javascript/19-Remove-Nth-Node-From-End-of-List.js
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * Definition for singly-linked list.
- * function ListNode(val, next) {
- * this.val = (val===undefined ? 0 : val)
- * this.next = (next===undefined ? null : next)
- * }
- */
-/**
- * @param {ListNode} head
- * @param {number} n
- * @return {ListNode}
- */
-var removeNthFromEnd = function(head, n) {
- let currNode = head;
- let nodeBeforeN = head;
-
- for (let i = 0; i < n; i++) {
- currNode = currNode.next;
- }
-
- if (!currNode) { return head.next }
-
- while (currNode.next) {
- nodeBeforeN = nodeBeforeN.next;
- currNode = currNode.next;
- }
-
- nodeBeforeN.next = nodeBeforeN.next.next;
-
- return head;
-
-};
diff --git a/javascript/191-Number-of-1-bits.js b/javascript/191-Number-of-1-bits.js
deleted file mode 100644
index ba44d4f22..000000000
--- a/javascript/191-Number-of-1-bits.js
+++ /dev/null
@@ -1,12 +0,0 @@
-/**
- * @param {number} n - a positive integer
- * @return {number}
- */
-var hammingWeight = function (n) {
- let output = 0;
- while (n != 0) {
- n &= (n - 1);
- output++;
- }
- return output;
-};
diff --git a/javascript/20-Valid-Parentheses.js b/javascript/20-Valid-Parentheses.js
deleted file mode 100644
index 149722b31..000000000
--- a/javascript/20-Valid-Parentheses.js
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * @param {string} s
- * @return {boolean}
- */
-var isValid = function(s) {
-
- let closeMap = {
- '}' :'{',
- ')' : '(',
- ']' : '['
- };
-
- let charStack = [];
-
- if (!s) return false;
-
- for (let i = 0; i < s.length; i++) {
- let curr = s.charAt(i);
- // check if closing bracket
- if (closeMap[curr]) {
- topElement = (charStack.length === 0) ? '#' : charStack.pop();
- if (topElement !== closeMap[curr]) {
- return false;
- }
- // opening bracket case
- } else {
- charStack.push(curr);
- }
- }
-
- return charStack.length === 0;
-};
diff --git a/javascript/200-Number-of-Islands.js b/javascript/200-Number-of-Islands.js
deleted file mode 100644
index 97daebf35..000000000
--- a/javascript/200-Number-of-Islands.js
+++ /dev/null
@@ -1,61 +0,0 @@
-// Version 1
-function explore(grid, r, c, visited) {
- const rowInbounds = 0 <= r && r < grid.length;
- const colInbounds = 0 <= c && c < grid[0].length;
-
- if (!rowInbounds || !colInbounds) return false;
- if (grid[r][c] === '0') return false;
-
- const pos = r + ',' + c;
-
- if (visited.has(pos)) return false;
- visited.add(pos);
-
- explore(grid, r - 1, c, visited);
- explore(grid, r + 1, c, visited);
- explore(grid, r, c - 1, visited);
- explore(grid, r, c + 1, visited);
-
- return true;
-}
-
-var numIslands = function (grid) {
- const visited = new Set();
- let count = 0;
-
- for (let r = 0; r < grid.length; r++) {
- for (let c = 0; c < grid[0].length; c++) {
- if (explore(grid, r, c, visited)) {
- count += 1;
- }
- }
- }
- return count;
-};
-
-// Version 2 (Easier to understand/read)
-function dfs(grid, i, j) {
- if (i < 0 || i >= grid.length || j < 0 || j >= grid[0].length || grid[i][j] === "0") {
- return;
- }
-
- grid[i][j] = "0";
- dfs(grid, i + 1, j);
- dfs(grid, i - 1, j);
- dfs(grid, i, j + 1);
- dfs(grid, i, j - 1);
-}
-
-var numIslands = function (grid) {
- let count = 0;
-
- for (let i = 0; i < grid.length; i++) {
- for (let j = 0; j < grid[0].length; j++) {
- if (grid[i][j] === "1") {
- count += 1;
- dfs(grid, i, j);
- }
- }
- }
- return count;
-};
\ No newline at end of file
diff --git a/javascript/206-Reverse-Linked-List.js b/javascript/206-Reverse-Linked-List.js
deleted file mode 100644
index 15bbbf0ff..000000000
--- a/javascript/206-Reverse-Linked-List.js
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * Definition for singly-linked list.
- * function ListNode(val, next) {
- * this.val = (val===undefined ? 0 : val)
- * this.next = (next===undefined ? null : next)
- * }
- */
-/**
- * @param {ListNode} head
- * @return {ListNode}
- */
-var reverseList = function(head) {
- let prev = null;
-
- while (head) {
- let next = head.next;
- head.next = prev;
- prev = head;
- head = next;
- }
-
- return prev;
-};
diff --git a/javascript/21-Merge-Two-Sorted-Lists.js b/javascript/21-Merge-Two-Sorted-Lists.js
deleted file mode 100644
index a9e155607..000000000
--- a/javascript/21-Merge-Two-Sorted-Lists.js
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * Definition for singly-linked list.
- * function ListNode(val, next) {
- * this.val = (val===undefined ? 0 : val)
- * this.next = (next===undefined ? null : next)
- * }
- */
-/**
- * @param {ListNode} list1
- * @param {ListNode} list2
- * @return {ListNode}
- */
-var mergeTwoLists = function(l1, l2) {
- let nullNode = { val : 0, next : null};
- let prev = nullNode;
- while (l1 && l2) {
- if (l1.val >= l2.val) {
- prev.next = l2;
- l2 = l2.next;
- } else {
- prev.next = l1;
- l1 = l1.next;
- }
- prev = prev.next;
- }
- prev.next = l1 || l2;
- return nullNode.next;
-};
diff --git a/javascript/210-Course-Schedule-II.js b/javascript/210-Course-Schedule-II.js
deleted file mode 100644
index e1ad55306..000000000
--- a/javascript/210-Course-Schedule-II.js
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * @param {number} numCourses
- * @param {number[][]} prerequisites
- * @return {number[]}
- */
- var findOrder = function(numCourses, prerequisites) {
- const prereq = [];
- for (let i = 0; i < numCourses; i++) {
- prereq[i] = [];
- };
- for (const [crs, pre] of prerequisites) {
- prereq[crs].push(pre);
- };
-
- const output = [];
- const visit = new Set();
- const cycle = new Set();
- function dfs(course) {
- if (cycle.has(course)) return false;
- if (visit.has(course)) return true;
-
- cycle.add(course);
- for (const pre of prereq[course]) {
- if (!dfs(pre)) return false;
- }
- cycle.delete(course);
- visit.add(course);
- output.push(course);
- return true;
- };
-
- for (let j = 0; j < numCourses; j++) {
- if (!dfs(j)) return [];
- };
- return output;
-};
\ No newline at end of file
diff --git a/javascript/213-House-Robber-II.js b/javascript/213-House-Robber-II.js
deleted file mode 100644
index 2264be082..000000000
--- a/javascript/213-House-Robber-II.js
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- * @param {number[]} nums
- * @return {number}
- */
- var rob = function(nums) {
- const n = nums.length;
- if (n == 1) return nums[0];
-
- function houseRobber(start, end) {
- let first = 0;
- let second = nums[start];
- for (let i = start +1; i < end; i++) {
- let temp = Math.max(first + nums[i], second);
- first = second;
- second = temp;
- };
- return second;
- };
-
- return Math.max(houseRobber(0, n-1), houseRobber(1, n));
-};
\ No newline at end of file
diff --git a/javascript/217-Contains-Duplicate.js b/javascript/217-Contains-Duplicate.js
deleted file mode 100644
index 3c96a1b20..000000000
--- a/javascript/217-Contains-Duplicate.js
+++ /dev/null
@@ -1,16 +0,0 @@
-/**
- * @param {number[]} nums
- * @return {boolean}
- */
-var containsDuplicate = function(nums) {
- let map = {};
-
- for (let i = 0; i < nums.length; i++) {
- if (nums[i] in map) {
- return true;
- } else {
- map[nums[i]] = i;
- }
- }
- return false;
-};
diff --git a/javascript/226-Invert-Binary-Tree.js b/javascript/226-Invert-Binary-Tree.js
deleted file mode 100644
index 33888e1d4..000000000
--- a/javascript/226-Invert-Binary-Tree.js
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * Definition for a binary tree node.
- * function TreeNode(val, left, right) {
- * this.val = (val===undefined ? 0 : val)
- * this.left = (left===undefined ? null : left)
- * this.right = (right===undefined ? null : right)
- * }
- */
-/**
- * @param {TreeNode} root
- * @return {TreeNode}
- */
-var invertTree = function(root) {
- if (!root) return root;
- let left = root.left;
- root.left = invertTree(root.right);
- root.right = invertTree(left);
- return root;
-
-};
diff --git a/javascript/23-Merge-K-Sorted-Lists.js b/javascript/23-Merge-K-Sorted-Lists.js
deleted file mode 100644
index 472a78762..000000000
--- a/javascript/23-Merge-K-Sorted-Lists.js
+++ /dev/null
@@ -1,29 +0,0 @@
-var merge = function (l1, l2) {
- let tempNode = new ListNode(0);
- let current = tempNode;
-
- while (l1 && l2) {
- if (l1.val < l2.val) {
- current.next = l1;
- l1 = l1.next;
- } else {
- current.next = l2;
- l2 = l2.next;
- }
- current = current.next;
- }
- if (l1) current.next = l1;
- if (l2) current.next = l2;
-
- return tempNode.next;
-}
-
-
-var mergeKLists = function (lists) {
- let root = lists[0];
-
- for (let i = 1; i < lists.length; i++) {
- root = merge(root, lists[i]);
- }
- return root || null;
-};
\ No newline at end of file
diff --git a/javascript/238-Product-of-Array-Except-Self.js b/javascript/238-Product-of-Array-Except-Self.js
deleted file mode 100644
index 819d9075b..000000000
--- a/javascript/238-Product-of-Array-Except-Self.js
+++ /dev/null
@@ -1,22 +0,0 @@
-/**
- * @param {number[]} nums
- * @return {number[]}
- */
-var productExceptSelf = function(nums) {
- const res = [];
-
- let product = 1;
-
- for (let i = 0; i < nums.length; i++) {
- res[i] = product;
- product *= nums[i];
- }
- product = 1;
- for (let j = nums.length - 1; j >= 0; j--) {
- res[j] *= product;
- product *= nums[j];
- }
-
- return res;
-
-};
diff --git a/javascript/239-Sliding-Window-Maximum.js b/javascript/239-Sliding-Window-Maximum.js
deleted file mode 100644
index 263022d39..000000000
--- a/javascript/239-Sliding-Window-Maximum.js
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * @param {number[]} nums
- * @param {number} k
- * @return {number[]}
- */
- function Node(value) {
- this.value = value;
- this.prev = null;
- this.next = null;
-};
-
-function Deque() {
- this.left = null;
- this.right = null;
- this.size = 0;
- this.pushRight = function(value) {
- const node = new Node(value);
- if (this.size == 0) {
- this.left = node;
- this.right = node;
- } else {
- this.right.next = node;
- node.prev = this.right;
- this.right = node;
- }
- this.size++;
- return this.size;
- };
- this.popRight = function() {
- if (this.size == 0) return null;
- const removedNode = this.right;
- this.right = this.right.prev;
- if (this.right) this.right.next = null;
- this.size--;
- return removedNode;
- };
- this.pushLeft = function(value) {
- const node = new Node(value);
- if (this.size == 0) {
- this.left = node;
- this.right = node;
- } else {
- this.left.prev = node;
- node.next = this.left;
- this.left = node;
- }
- this.size++;
- return this.size;
- };
- this.popLeft = function() {
- if (this.size == 0) return null;
- const removedNode = this.left;
- this.left = this.left.next;
- if (this.left) this.left.prev = null;
- this.size--;
- return removedNode;
- };
-};
-
-var maxSlidingWindow = function(nums, k) {
- const output = [];
- let deque = new Deque();
- let left = 0;
- let right = 0;
-
- while (right < nums.length) {
- // pop smaller values from q
- while (deque.right && nums[deque.right.value] < nums[right]) deque.popRight();
- deque.pushRight(right);
-
- // remove left val from window
- if (left > deque.left.value) deque.popLeft();
-
- if (right +1 >= k) {
- output.push(nums[deque.left.value]);
- left++;
- };
- right++;
- };
- return output;
-};
\ No newline at end of file
diff --git a/javascript/242-Valid-Anagram.js b/javascript/242-Valid-Anagram.js
deleted file mode 100644
index 0447a7774..000000000
--- a/javascript/242-Valid-Anagram.js
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * @param {string} s
- * @param {string} t
- * @return {boolean}
- */
-var isAnagram = function(s, t) {
- let map = {};
-
- if (s.length !== t.length) {
- return false;
- }
-
- for (let i = 0; i < s.length; i++) {
- if (map[s[i]]) {
- map[s[i]]++;
- } else {
- map[s[i]] = 1;
- }
- }
-
- for (let i = 0; i < t.length; i++) {
- if (map[t[i]]) {
- map[t[i]]--;
- } else {
- return false;
- }
- }
-
- return true;
-
-
-
-
-};
diff --git a/javascript/3-Longest-Substring-Without-Repeating-Characters.js b/javascript/3-Longest-Substring-Without-Repeating-Characters.js
deleted file mode 100644
index 6969dd390..000000000
--- a/javascript/3-Longest-Substring-Without-Repeating-Characters.js
+++ /dev/null
@@ -1,22 +0,0 @@
-var lengthOfLongestSubstring = function (str) {
- const hash = {};
- let start = 0;
- let max = 0;
-
- for (let i = 0; i < str.length; i++) {
- let rightChar = str[i];
-
- if (!(rightChar in hash)) hash[rightChar] = 0;
- hash[rightChar] += 1;
-
- while (hash[rightChar] > 1) {
- let leftChar = str[start];
- start += 1;
-
- if (leftChar in hash) hash[leftChar] -= 1;
- if (hash[leftChar] === 0) delete hash[leftChar];
- }
- max = Math.max(max, i - start + 1);
- }
- return max;
-};
\ No newline at end of file
diff --git a/javascript/300-Longest-Increasing-Subsequence.js b/javascript/300-Longest-Increasing-Subsequence.js
deleted file mode 100644
index d7b63b06c..000000000
--- a/javascript/300-Longest-Increasing-Subsequence.js
+++ /dev/null
@@ -1,12 +0,0 @@
-var lengthOfLIS = function(nums) {
- let arr = Array(nums.length).fill(1);
-
- for(let i = 1; i < arr.length; i++) {
- for (let j = 0; j < i; j++) {
- if (nums[i] > nums[j]) {
- arr[i] = Math.max(arr[i], arr[j] + 1);
- }
- }
- }
- return Math.max(...arr);
-};
diff --git a/javascript/322-Coin-Change.js b/javascript/322-Coin-Change.js
deleted file mode 100644
index 165a8408b..000000000
--- a/javascript/322-Coin-Change.js
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
- * @param {number[]} coins
- * @param {number} amount
- * @return {number}
- */
-var coinChange = function(coins, amount) {
- let dp = Array(amount+1).fill(amount+1)
- dp[0]=0
- for(let i=1; i= 0) {
- dp[i] = Math.min(dp[i], 1 + dp[i-coin])
- }
- }
- }
- return dp[amount] === amount+1 ? -1 : dp.pop()
-};
diff --git a/javascript/33-Search-in-Rotated-Sorted-Array.js b/javascript/33-Search-in-Rotated-Sorted-Array.js
deleted file mode 100644
index 97d83dcc9..000000000
--- a/javascript/33-Search-in-Rotated-Sorted-Array.js
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * @param {number[]} nums
- * @param {number} target
- * @return {number}
- */
-var search = function(nums, target) {
- let left = 0;
- let right = nums.length - 1;
-
- while (left <= right) {
- let mid = Math.floor((left + right) / 2);
-
- if (nums[mid] === target) {
- return mid;
- }
-
- // Checking if the left side is sorted
- if (nums[left] <= nums[mid]) {
- if (nums[left] <= target && target <= nums[mid]) {
- // thus target is in the left
- right = mid - 1;
-
- } else {
- // thus target is in the right
- left = mid + 1;
- }
- }
-
- // Otherwise, the right side is sorted
- else {
- if (nums[mid] <= target && target <= nums[right]) {
- // thus target is in the right
- left = mid + 1;
-
- } else {
- // thus target is in the left
- right = mid - 1;
- }
- }
-
- }
-
- return -1;
-};
diff --git a/javascript/338-Counting-Bits.js b/javascript/338-Counting-Bits.js
deleted file mode 100644
index f6251cd34..000000000
--- a/javascript/338-Counting-Bits.js
+++ /dev/null
@@ -1,11 +0,0 @@
-/**
- * @param {number} n
- * @return {number[]}
- */
-var countBits = function (n) {
- let output = [0];
- for (let i = 1; i < n + 1; i++) {
- output.push((output[i >> 1] + (i & 1)));
- }
- return output;
-};
diff --git a/javascript/347-Top-K-Frquent-Elements.js b/javascript/347-Top-K-Frquent-Elements.js
deleted file mode 100644
index 910c74b3d..000000000
--- a/javascript/347-Top-K-Frquent-Elements.js
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * @param {number[]} nums
- * @param {number} k
- * @return {number[]}
- */
-var topKFrequent = function(nums, k) {
- let map = new Map();
- let res = [];
- let bucket = new Array(nums.length+1);
-
- // storing frequency of numbers in a map
- for (let n of nums) {
- map.set(n, (map.has(n) ? 1 + map.get(n) : 1))
- }
-
- // Poppulate the bucket with numbers in frequency
- // as the index of the bucket
- for (let [key,value] of map.entries()) {
- if (!Array.isArray(bucket[value])) {
- bucket[value] = [];
- }
- bucket[value].push(key);
- }
-
- for (let i = bucket.length-1; i >= 0; i--) {
- if (Array.isArray(bucket[i])) {
- for (let n of bucket[i]) {
- res.push(n);
- if (res.length === k)
- return res;
- }
- }
- }
-};
\ No newline at end of file
diff --git a/javascript/49-Group-Anagrams.js b/javascript/49-Group-Anagrams.js
deleted file mode 100644
index e5acf6a64..000000000
--- a/javascript/49-Group-Anagrams.js
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * @param {string[]} strs
- * @return {string[][]}
- */
-const groupAnagrams = (strs) => {
- const result = [];
- const map = new Map();
- for (let i = 0; i < strs.length; i++) {
- const sorted = strs[i].split("").sort().join("");
- //! we are just splitting the string and sorting it and joining it back
- console.log(sorted);
- if (map.has(sorted)) {
- map.get(sorted).push(strs[i]); //! if the map has the sorted string, we push the string into the array
- } else {
- map.set(sorted, [strs[i]]); //! we are pushing the string into the map with the sorted string as the key
- }
- }
-
- for (let [key, value] of map) {
- result.push(value);
- }
- return result;
-};
diff --git a/javascript/49-Rotate-Image.js b/javascript/49-Rotate-Image.js
deleted file mode 100644
index 7508b0a8d..000000000
--- a/javascript/49-Rotate-Image.js
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * @param {number[][]} matrix
- * @return {void} Do not return anything, modify matrix in-place instead.
- */
-var rotate = function(matrix) {
- transpose(matrix);
- reflect(matrix);
-};
-
-var transpose = function(matrix) {
- let n = matrix.length;
- for (let i = 0; i < n; i++) {
- for (let j = i + 1; j < n; j++) {
- let temp = matrix[j][i];
- matrix[j][i] = matrix[i][j];
- matrix[i][j] = temp;
- }
- }
-}
-
-var reflect = function(matrix) {
- let n = matrix.length;
- for (let i = 0; i < n; i++) {
- for (let j = 0; j < n / 2; j++) {
- let temp = matrix[i][j];
- matrix[i][j] = matrix[i][n - j - 1];
- matrix[i][n - j - 1] = temp;
- }
- }
-}
diff --git a/javascript/53-Maximum-Subarray.js b/javascript/53-Maximum-Subarray.js
deleted file mode 100644
index 171bcbfc4..000000000
--- a/javascript/53-Maximum-Subarray.js
+++ /dev/null
@@ -1,14 +0,0 @@
-/**
- * @param {number[]} nums
- * @return {number}
- */
-var maxSubArray = function(nums) {
- let curr = nums[0];
- let max = nums[0];
-
- for (let i = 1; i < nums.length; i++) {
- curr = Math.max(curr + nums[i], nums[i]);
- max = Math.max(max, curr)
- }
- return max;
-};
diff --git a/javascript/54-Spiral-Matrix.js b/javascript/54-Spiral-Matrix.js
deleted file mode 100644
index 9d27c5f4c..000000000
--- a/javascript/54-Spiral-Matrix.js
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * @param {number[][]} matrix
- * @return {number[]}
- */
-var spiralOrder = function(matrix) {
- const results = []
- let startRow = 0, startCol = 0, endRow = matrix.length-1, endCol = matrix[0].length-1;
-
- while(results.length < matrix.length * matrix[0].length) {
-
- for(let col = startCol; col <= endCol; col++ ) {
- results.push(matrix[startRow][col])
- }
-
- for(let row = startRow + 1; row <= endRow; row++) {
- results.push(matrix[row][endCol])
- }
-
- for(let col = endCol - 1; col >= startCol; col--) {
- if(startRow === endRow) break;
- results.push(matrix[endRow][col])
- }
-
- for(let row = endRow - 1; row >= startRow + 1; row--) {
- if(endCol === startCol) break;
- results.push(matrix[row][startCol])
- }
-
- startRow++
- startCol++
- endRow--
- endCol--
- }
-
- return results
-};
diff --git a/javascript/56-Merge-Intervals.js b/javascript/56-Merge-Intervals.js
deleted file mode 100644
index ebacd2a10..000000000
--- a/javascript/56-Merge-Intervals.js
+++ /dev/null
@@ -1,16 +0,0 @@
-var merge = function (intervals) {
- intervals.sort((a, b) => a[0] - b[0]);
-
- let res = [intervals[0]];
-
- for (let i = 1; i < intervals.length; i++) {
- let prev = res[res.length - 1];
-
- if (prev[1] >= intervals[i][0]) {
- prev[1] = Math.max(prev[1], intervals[i][1]);
- } else {
- res.push(intervals[i]);
- }
- }
- return res;
-};
\ No newline at end of file
diff --git a/javascript/572-Subtree-of-Another-Tree.js b/javascript/572-Subtree-of-Another-Tree.js
deleted file mode 100644
index 1820a9534..000000000
--- a/javascript/572-Subtree-of-Another-Tree.js
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Definition for a binary tree node.
- * function TreeNode(val, left, right) {
- * this.val = (val===undefined ? 0 : val)
- * this.left = (left===undefined ? null : left)
- * this.right = (right===undefined ? null : right)
- * }
- */
-/**
- * @param {TreeNode} root
- * @param {TreeNode} subRoot
- * @return {boolean}
- */
-var isSubtree = function(root, subRoot) {
-
- // given two nodes are they the same?
- const isSame = (n1, n2) => {
- if (!n1 && !n2) return true;
- if (!n1 || !n2 || n1.val !== n2.val) return false;
- return isSame(n1.left, n2.left) && isSame(n1.right, n2.right);
- }
-
- // check if subRoot is subtree of root:
- const DFS = (node) => {
- if (!node) return false;
- if (isSame(node, subRoot)) return true;
- return DFS(node.left) || DFS(node.right);
- }
-
-
- return DFS(root);
-
-
-};
diff --git a/javascript/70-Climbing-Stairs.js b/javascript/70-Climbing-Stairs.js
deleted file mode 100644
index 2d02c4faf..000000000
--- a/javascript/70-Climbing-Stairs.js
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * @param {number} n
- * @return {number}
- */
-var climbStairs = function(n) {
- const memoized = climb();
- return memoized(n);
-};
-
-function climb() {
- let cache = {};
-
- return function climbStairs(n) {
- if (n in cache) {
- return cache[n];
- } else if (n >= 1 && n < 4) {
- return n;
- } else {
- cache[n] = climbStairs(n-2) + climbStairs(n-1);
- return cache[n];
- }
- }
-}
diff --git a/javascript/704-Binary-Search.js b/javascript/704-Binary-Search.js
deleted file mode 100644
index c334eac1e..000000000
--- a/javascript/704-Binary-Search.js
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * @param {number[]} nums
- * @param {number} target
- * @return {number}
- */
-var search = function (nums, target) {
-
- let left = 0;
- let right = nums.length - 1;
-
- while (left <= right) {
- let middle = Math.floor((left + right) / 2);
-
- if (nums[middle] === target) {
- return middle;
- } else if (nums[middle] < target) {
- left = middle + 1;
- } else {
- right = middle - 1;
- }
- }
-
- return -1;
-};
-
-// Runtime: 98 ms, faster than 34.02% of JavaScript online submissions for Binary Search.
-// Memory Usage: 44.3 MB, less than 99.18% of JavaScript online submissions for Binary Search.
\ No newline at end of file
diff --git a/javascript/73-Set-Matrix-Zeroes.js b/javascript/73-Set-Matrix-Zeroes.js
deleted file mode 100644
index 36068902c..000000000
--- a/javascript/73-Set-Matrix-Zeroes.js
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * @param {number[][]} matrix
- * @return {void} Do not return anything, modify matrix in-place instead.
- */
-var setZeroes = function(matrix) {
- let row = new Array(matrix.length);
- let col = new Array(matrix[0].length);
-
- for (let i = 0; i < row.length; i++) {
- for (let j = 0; j < col.length; j++) {
- if (matrix[i][j] === 0) {
- row[i] = 0;
- col[j] = 0;
- }
- }
- }
-
- for (let i = 0; i < row.length; i++) {
- for (let j = 0; j < col.length; j++) {
- if (row[i] == 0 || col[j] == 0) {
- matrix[i][j] = 0;
- }
- }
- }
-
-};
diff --git a/javascript/76-Minimum-Window-Substring.js b/javascript/76-Minimum-Window-Substring.js
deleted file mode 100644
index 990a37b1d..000000000
--- a/javascript/76-Minimum-Window-Substring.js
+++ /dev/null
@@ -1,35 +0,0 @@
-var minWindow = function (str, target) {
- const hash = target.split('').reduce((acc, val) => {
- if (!acc[val]) acc[val] = 0;
- acc[val] += 1;
- return acc;
- }, {})
-
- let start = 0;
- let min = Infinity;
- let matched = 0;
- let subStringStart = null;
-
- for (let i = 0; i < str.length; i++) {
- let rightChar = str[i];
-
- if (rightChar in hash) hash[rightChar] -= 1;
- if (hash[rightChar] >= 0) matched += 1;
-
- while (matched === target.length) {
- if (i - start + 1 < min) {
- subStringStart = start;
- min = i - start + 1;
- }
-
- let leftChar = str[start];
- start += 1;
-
- if (leftChar in hash) {
- if (hash[leftChar] === 0) matched -= 1;
- hash[leftChar] += 1;
- }
- }
- }
- return min === Infinity ? '' : str.substring(subStringStart, subStringStart + min);
-};
\ No newline at end of file
diff --git a/javascript/79-Word-Search.js b/javascript/79-Word-Search.js
deleted file mode 100644
index 437bd351f..000000000
--- a/javascript/79-Word-Search.js
+++ /dev/null
@@ -1,29 +0,0 @@
-function dfs(board, i, j, remain) {
- if (remain === "") return true;
- if (i < 0 || i >= board.length || j < 0 || j >= board[0].length) return false;
- if (board[i][j] !== remain[0]) return false;
-
- let temp = board[i][j];
- board[i][j] = "-";
-
- let result = (
- dfs(board, i - 1, j, remain.slice(1))
- || dfs(board, i + 1, j, remain.slice(1))
- || dfs(board, i, j - 1, remain.slice(1))
- || dfs(board, i, j + 1, remain.slice(1))
- )
-
- board[i][j] = temp;
- return result;
-}
-
-var exist = function (board, word) {
- for (let i = 0; i < board.length; i++) {
- for (let j = 0; j < board[0].length; j++) {
- if (dfs(board, i, j, word)) {
- return true;
- }
- }
- }
- return false;
-};
\ No newline at end of file
diff --git a/javascript/9-Palindrome-Number.js b/javascript/9-Palindrome-Number.js
deleted file mode 100644
index df0f55dbe..000000000
--- a/javascript/9-Palindrome-Number.js
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * @param {number} x
- * @return {boolean}
- */
-var isPalindrome = function (x) {
-
- // Creates array from int characters
- // 121 -> [1,2,1]
- let arr = Array.from(String(x), Number);
-
- // Uses two pointer
- for (let i = 0; i < arr.length; i++) {
- if (arr[i] !== arr[arr.length - 1 - i]) {
- return false;
- }
- }
-
- return true;
-};
-
-
-// Runtime: 302 ms, faster than 40.50% of JavaScript online submissions for Palindrome Number.
-// Memory Usage: 51.8 MB, less than 8.36% of JavaScript online submissions for Palindrome Number.
-
diff --git a/javascript/98-Validate-Binary-Search-Tree.js b/javascript/98-Validate-Binary-Search-Tree.js
deleted file mode 100644
index 3d7cad0de..000000000
--- a/javascript/98-Validate-Binary-Search-Tree.js
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * Definition for a binary tree node.
- * function TreeNode(val, left, right) {
- * this.val = (val===undefined ? 0 : val)
- * this.left = (left===undefined ? null : left)
- * this.right = (right===undefined ? null : right)
- * }
- */
-/**
- * @param {TreeNode} root
- * @return {boolean}
- */
-
-
-var isValidBST = function(root) {
- return validate(root, null, null);
-};
-
-function validate(root, max, min) {
- if (!root) {
- return true;
- } else if (max !== null && root.val >= max || min !== null && root.val <= min) {
- return false;
- } else
- return validate(root.left, root.val, min) && validate(root.right, max, root.val);
-}
diff --git a/swift/1-Two-Sum.swift b/swift/1-Two-Sum.swift
deleted file mode 100644
index ab3a65250..000000000
--- a/swift/1-Two-Sum.swift
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- * Question Link: https://leetcode.com/problems/two-sum/
- */
-
-class TwoSum {
- func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
- var prevMap = [Int:Int]() // val -> index
-
- for (i, n) in nums.enumerated() {
- let diff = target - n
- if let firstIndex = prevMap[diff] {
- return [firstIndex, i]
- }
- prevMap[n] = i
- }
- return []
- }
-}
diff --git a/swift/217-Contains-Duplicate.swift b/swift/217-Contains-Duplicate.swift
deleted file mode 100644
index 2c550af5f..000000000
--- a/swift/217-Contains-Duplicate.swift
+++ /dev/null
@@ -1,16 +0,0 @@
-/**
- * Question Link: https://leetcode.com/problems/contains-duplicate/
- */
-
-class ContainsDuplicate {
- func containsDuplicate(_ nums: [Int]) -> Bool {
- var hashSet = Set()
- for n in nums {
- if hashSet.contains(n) {
- return true
- }
- hashSet.insert(n)
- }
- return false
- }
-}
diff --git a/swift/238-Product-of-array-except-self.swift b/swift/238-Product-of-array-except-self.swift
deleted file mode 100644
index 761021d6c..000000000
--- a/swift/238-Product-of-array-except-self.swift
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
-* Question Link: https://leetcode.com/problems/product-of-array-except-self/
-*/
-
-class ProductExceptSelf {
- func productExceptSelf(_ nums: [Int]) -> [Int] {
- var res = [Int](repeating: 1, count: nums.count)
-
- var prefix = 1
- for i in 0.. [Int] {
- var count = [Int:Int]()
- for n in nums {
- guard count[n] != nil else {
- count[n] = 1
- continue
- }
- count[n] = 1 + count[n]!
- }
-
- var freq = [[Int]](repeating: [], count: nums.count+1)
- for (n, c) in count {
- freq[c].append(n)
- }
-
- var res = [Int]()
- for i in stride(from: freq.count-1, to: 0, by: -1) {
- for n in freq[i] {
- res.append(n)
- if res.count == k {
- return res
- }
- }
- }
- return res
- }
-}