Skip to content

Instantly share code, notes, and snippets.

@shanecandoit
shanecandoit / reverseParentheses.py
Created July 11, 2024 15:55
1190. Reverse Substrings Between Each Pair of Parentheses
class Solution:
def reverseParentheses(self, s: str) -> str:
""" Reverse Substrings Between Each Pair of Parentheses
You are given a string s that consists of lower case English letters and brackets.
Reverse the strings in each pair of matching parentheses, starting from the innermost one.
Your result should not contain any brackets.
Example 1:
class Solution:
def isMatch(self, s: str, p: str) -> bool:
"""44. Wildcard Matching
Given an input string (s) and a pattern (p),
implement wildcard pattern matching with support for '?' and '*' where:
'?' Matches any single character.
'*' Matches any sequence of characters (including the empty sequence).
The matching should cover the entire input string (not partial).
from typing import List
class Solution:
def canJump(self, nums: List[int]) -> bool:
"""
55. Jump Game
You are given an integer array nums.
You are initially positioned at the array's first index,
and each element in the array represents your maximum jump length at that position.
@shanecandoit
shanecandoit / longest_valid_parentheses.py
Created June 12, 2024 15:32
longest valid parens using a stack
"""
32. Longest Valid Parentheses
Hard
Given a string containing just the characters '(' and ')', return the length of the longest valid (well-formed) parentheses
substring
Example 1:
Input: s = "(()"
@shanecandoit
shanecandoit / unique-paths-py
Created June 10, 2024 22:01
unique paths to end of maze, solve back to front
# https://leetcode.com/problems/unique-paths/description/
"""
62. Unique Paths
Medium
Topics
Companies
There is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner (i.e., grid[m - 1][n - 1]). The robot can only move either down or right at any point in time.
@shanecandoit
shanecandoit / roman-to-integer.py
Created June 7, 2024 18:13
Convert roman numerals to integers
"""
https://leetcode.com/problems/roman-to-integer/description/
13. Roman to Integer
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.
Symbol Value
I 1
V 5
@shanecandoit
shanecandoit / scratch.py
Created June 7, 2024 18:04
leetcode 648 replace words
"""
https://leetcode.com/problems/replace-words/submissions/1280805154/?envType=daily-question&envId=2024-06-07
648. Replace Words
Medium
Topics
Companies
In English, we have a concept called root, which can be followed by some other word to form another longer word - let's call this word derivative. For example, when the root "help" is followed by the word "ful", we can form a derivative "helpful".
import random
import string
def generate_slug(pattern='cvccvc-cvccvc-xxxxxx-cvccvc-000'):
""" Return something like 'pevqak-jaxkev-evryfd-IGyv-45v94'
given a pattern like: 'cvccvc-cvccvc-xxxxxx-XXxx-00x00'
"""
vowels = 'aeiou'
consonants = 'bcdfghjklmnpqrstvwxyz'
@shanecandoit
shanecandoit / csv_to_markdown_to_html.py
Created June 28, 2023 21:30
Turn csv text into markdown tables and also into html
def csv_to_markdown_table(csv_string):
"""
Convert a csv style string to a markdown table string.
Args:
csv_string: The csv style string to convert.
Returns:
The markdown table string.
@shanecandoit
shanecandoit / list-tokens-hash.ipynb
Last active March 3, 2023 23:52
python_list_tokens_hashing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.