This file contains hidden or 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 reverseList(self, head): | |
| """ | |
| :type head: ListNode |
This file contains hidden or 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 mostCommonWord(self, paragraph, banned): | |
| """ | |
| :type paragraph: str | |
| :type banned: List[str] | |
| :rtype: str | |
| """ | |
| p = re.compile(r"[!?',;.]") | |
| paraStrs = p.sub('', paragraph.lower()).split(' ') | |
This file contains hidden or 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
| 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 |
This file contains hidden or 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 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} | |
This file contains hidden or 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
| func lemonadeChange(bills []int) bool { | |
| numFive :=0 | |
| numTen :=0 | |
| numTwenty :=0 | |
| for i := range bills { | |
| switch bills[i] { | |
| case 5: | |
| numFive +=1 | |
| case 10 : |
This file contains hidden or 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 lemonadeChange(self, bills): | |
| """ | |
| :type bills: List[int] | |
| :rtype: bool | |
| """ | |
| numFive = 0 | |
| numTen = 0 | |
| numTwenty = 0 | |
This file contains hidden or 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
| 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) | |
This file contains hidden or 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 countBinarySubstrings(self, s): | |
| """ | |
| :type s: str | |
| :rtype: int | |
| """ | |
| size = len(s) | |
| cnt = [0, 0] | |
| last = None | |
| ans = 0 |
This file contains hidden or 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
| 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++ |
This file contains hidden or 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
| func rotatedDigits(N int) int { | |
| count := 0 | |
| for i :=2; i <= N; i++ { | |
| if isValid(i) { | |
| count++ | |
| } | |
| } | |
| return count | |
| } |