Skip to content

Instantly share code, notes, and snippets.

View luojiyin1987's full-sized avatar
💭
I may be slow to respond.

luo jiyin luojiyin1987

💭
I may be slow to respond.
View GitHub Profile
@luojiyin1987
luojiyin1987 / Reverse Linked List.py
Created July 31, 2018 09:37
Reverse Linked List
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def reverseList(self, head):
"""
:type head: ListNode
@luojiyin1987
luojiyin1987 / Most Common Word.py
Created July 31, 2018 09:09
Most Common Word
class Solution:
def mostCommonWord(self, paragraph, banned):
"""
:type paragraph: str
:type banned: List[str]
:rtype: str
"""
p = re.compile(r"[!?',;.]")
paraStrs = p.sub('', paragraph.lower()).split(' ')
@luojiyin1987
luojiyin1987 / Roman to Integer.go
Created July 28, 2018 10:57
Roman to Integer
func romanToInt(s string) int {
numbers := map[string]int{"M":1000, "D":500, "C":100, "L":50, "X":10, "V":5, "I":1}
last := -1
sum := 0
bytes := []byte(s)
for i := range bytes{
if last > 0 && numbers[string(bytes[i])] > last {
sum -= 2 * last
@luojiyin1987
luojiyin1987 / Roman to Integer.py
Created July 28, 2018 10:38
Roman to Integer
class Solution:
def romanToInt(self, s):
"""
:type s: str
:rtype: int
"""
sum = 0
last = None
numbers = {"M":1000, "D":500, "C":100, "L":50, "X":10, "V":5, "I":1}
func lemonadeChange(bills []int) bool {
numFive :=0
numTen :=0
numTwenty :=0
for i := range bills {
switch bills[i] {
case 5:
numFive +=1
case 10 :
class Solution:
def lemonadeChange(self, bills):
"""
:type bills: List[int]
:rtype: bool
"""
numFive = 0
numTen = 0
numTwenty = 0
func rotateString(A string, B string) bool {
if len(A) != len(B) {
return false
} else if (len(A) == 0 && len(B)==0) {
return true
}
bytes := []byte(A)
l := len(bytes)
@luojiyin1987
luojiyin1987 / Count Binary Substrings.py
Created July 24, 2018 09:24
Count Binary Substrings
class Solution:
def countBinarySubstrings(self, s):
"""
:type s: str
:rtype: int
"""
size = len(s)
cnt = [0, 0]
last = None
ans = 0
@luojiyin1987
luojiyin1987 / Count Binary Substrings.py
Created July 24, 2018 09:13
Count Binary Substrings
func countBinarySubstrings(s string) int {
count, countZero, countOne := 0, 0, 0
prev := rune(s[0])
for _, r := range s {
if prev == r {
if r == '0' {
countZero++
} else {
countOne++
func rotatedDigits(N int) int {
count := 0
for i :=2; i <= N; i++ {
if isValid(i) {
count++
}
}
return count
}