Skip to content

Instantly share code, notes, and snippets.

@farkwun
farkwun / convert_textile_to_markdown.rake
Last active February 1, 2016 21:19
Convert textile to Markdown Extra - shamelessly derived from https://gist.github.com/othree/8563b7f9018730666b95
task :convert_textile_to_markdown_extra => :environment do
require 'tempfile'
Issue.all.each do |version|
if (String(version.tracker) == "Approval" && Integer(version.id) > 72400 && Integer(version.id) < 72500)
#if (Integer(version.id) == 73293) for testing on specific documents
puts 'Converting Issue...'
puts version.id
puts version.subject
@farkwun
farkwun / solution.py
Last active June 20, 2017 05:37
17. Letter Combinations of a Phone Number - Leetcode
# https://leetcode.com/problems/letter-combinations-of-a-phone-number/#/description
class Solution(object):
DIGIT_DICT = {
"2" : ['a', 'b', 'c'],
"3" : ['d', 'e', 'f'],
"4" : ['g', 'h', 'i'],
"5" : ['j', 'k', 'l'],
"6" : ['m', 'n', 'o'],
"7" : ['p', 'q', 'r', 's'],
"8" : ['t', 'u', 'v'],
@farkwun
farkwun / solution.py
Created June 20, 2017 05:36
22. Generate Parentheses - Leetcode
# https://leetcode.com/problems/generate-parentheses/#/description
class Solution(object):
def generateParenthesis(self, n):
"""
:type n: int
:rtype: List[str]
"""
return(self.createParentheses("", n, n))
def createParentheses(self, string, num_open, num_closed):
@farkwun
farkwun / solution.py
Created June 20, 2017 06:07
20. Valid Parentheses - Leetcode
# https://leetcode.com/problems/valid-parentheses/#/description
class Solution(object):
CLOSED_BRACKET_DICT = {
')' : '(',
'}' : '{',
']' : '['
}
def isValid(self, s):
"""
:type s: str
@farkwun
farkwun / solution477.py
Created August 18, 2017 23:12
477. Total Hamming Distance
# https://leetcode.com/problems/total-hamming-distance/description/
class Solution(object):
def totalHammingDistance(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
i = 0
@farkwun
farkwun / solution454.py
Created August 18, 2017 23:12
454. 4Sum II
# https://leetcode.com/problems/4sum-ii/description/
class Solution(object):
def fourSumCount(self, A, B, C, D):
"""
:type A: List[int]
:type B: List[int]
:type C: List[int]
:type D: List[int]
:rtype: int
"""
@farkwun
farkwun / solution343.py
Created August 18, 2017 23:13
343. Integer Break
# https://leetcode.com/problems/integer-break/description/
class Solution(object):
def integerBreak(self, n):
"""
:type n: int
:rtype: int
"""
if n == 1 or n == 2:
return 1
@farkwun
farkwun / solution628.py
Created August 20, 2017 07:23
628. Maximum Product of Three Numbers
# https://leetcode.com/problems/maximum-product-of-three-numbers/description/
class Solution(object):
def maximumProduct(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
length = len(nums)
if length == 3:
@farkwun
farkwun / solution504.py
Created August 20, 2017 07:24
504. Base 7
# https://leetcode.com/problems/base-7/description/
class Solution(object):
BASE_EXP = [1, 7, 49, 343, 2401, 16807, 117649, 823543, 5764801, 40353607]
def convertToBase7(self, num):
"""
:type num: int
:rtype: str
"""
def add_x_to_digits(x, digit_list):
@farkwun
farkwun / solution543.py
Created August 20, 2017 07:25
543. Diameter of Binary Tree
# https://leetcode.com/problems/diameter-of-binary-tree/description/
# 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):