This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The PiStation Case (for the Raspberry Pi 4) | |
# is a well built fun case, especially for those | |
# with a passion for retro-gaming consoles. | |
# Personally, I love it. | |
# | |
# - https://shop.pimoroni.com/products/pistation-case | |
# | |
# But installing the 'safe shutdown' feature may get you frustrated. | |
# The hardware's brilliant, but the shutdown script installation | |
# needs a little work. There are a number of |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
class Node( object ): | |
def __init__( self, end_node = False ): | |
self.end_node = end_node | |
self.prefix_count = 0 | |
self.children = {} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def jump(self, nums): | |
""" | |
:type nums: List[int] | |
:rtype: int | |
""" | |
if not nums or len(nums) == 1: | |
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Good morning! Here's your coding interview problem for today. | |
This problem was asked by Amazon. | |
Given a string s and an integer k, break up the string into multiple texts such that each text has a length of k or less. | |
You must break it up so that words don't break across lines. If there's no way to break the text up, then return null. | |
You can assume that there are no spaces at the ends of the string and that there is exactly one space between each word. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution(object): | |
def totalNQueens(self, n): | |
""" | |
:type n: int | |
:rtype: int | |
""" | |
positions = [None]*n | |
_, count = self.solve(n, 0, positions, count=0) | |
return count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MaxHeapObj: | |
def __init__(self,val): self.val = val | |
def __lt__(self,other): return self.val > other.val | |
def __eq__(self,other): return self.val == other.val | |
def __str__(self): return str(self.val) | |
class MinHeap: | |
def __init__(self): self.h = [] | |
def heappush(self,x): heapq.heappush(self.h,x) | |
def heappop(self): return heapq.heappop(self.h) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definition for a binary tree node. | |
# class TreeNode(object): | |
# def __init__(self, x): | |
# self.val = x | |
# self.left = None | |
# self.right = None | |
class Solution(object): | |
def kthSmallest(self, root, k): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definition for singly-linked list. | |
# class ListNode: | |
# def __init__(self, x): | |
# self.val = x | |
# self.next = None | |
class Solution: | |
def removeNthFromEnd(self, head, k): | |
""" | |
:type head: ListNode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def backspaceCompare(self, S, T): | |
""" | |
:type S: str | |
:type T: str | |
:rtype: bool | |
""" | |
pointerS, pointerT = len(S)-1, len(T)-1 | |
skipS, skipT = 0, 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definition for singly-linked list. | |
# class ListNode(object): | |
# def __init__(self, x): | |
# self.val = x | |
# self.next = None | |
class Solution(object): | |
def getLength(self, node): | |
length = 0 | |
while node: |
NewerOlder