Skip to content

Instantly share code, notes, and snippets.

View HauptJ's full-sized avatar
:octocat:
Tschüss STL

Joshua Haupt HauptJ

:octocat:
Tschüss STL
View GitHub Profile
class Solution:
def repeatedNTimes(self, A: List[int]) -> int:
for i in range(len(A)):
if A.count(A[i]) == len(A)//2:
return A[i]
"""
class Solution:
def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool:
if not matrix:
return False
rows = len(matrix)
cols = len(matrix[0])
for i in range(0, rows-1, 1):
class Solution:
def merge(self, intervals: List[List[int]]) -> List[List[int]]:
if not intervals:
return []
n = len(intervals)-1
intervals.sort()
"Find and fix bugs in a function that sums all elements in an array."
Number of candies Mary can give to her brother.
She has an array of candies [3, 4, 5, 5, 7, 7] ans = 3
She has to give 1/2 to her brother. and wants to eat as many unique candies as possible. What is the max number of unique candies she can eat?
```
class Solution:
def get_number_of_islands(binaryMatrix):
if not binaryMatrix:
return 0
islands = 0
def dfs(grid, i, j):
if i < 0 or j < 0 or i >= len(grid) or j >= len(grid[0]) or grid[i][j] == 0:
return True
def find_array_quadruplet(arr, s):
if not arr or len(arr) < 4:
return []
n = len(arr)
arr.sort()
for i in range(0, n-3):
@HauptJ
HauptJ / CellularAutomata.py
Created February 3, 2020 01:19
Cellular Automata
def cellCompete(states, days):
print("INIT STATES: " + str(len(states)))
for day in range(days):
nextGen = []
print("DAY: " + str(day))
print("NO STATES: " + str(len(states)))
for i in range(0, len(states)):
print(i)
func reverse(x int) int {
res := 0
for x!= 0 {
res = res*10+x%10
x=x/10
if res != int(int32(res)){
return 0
}
}
return res
class Solution:
def moveZeroes(self, nums: List[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
count = nums.count(0)
nums[:] = list(filter(lambda a: a != 0, nums))
for i in range(count, 0, -1):
nums.append(0)
class Solution:
def firstMissingPositive(self, nums: List[int]) -> int:
i = 1
if i not in nums:
return i
for num in nums:
if i in nums:
i += 1