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 readBinaryWatch(self, num: int) -> List[str]: | |
"""copy from 思君满月""" | |
ret = [] | |
for hour in range(12): | |
for minute in range(60): | |
if (bin(hour) + bin(minute)).count('1') == num: | |
ret.append('%d:%02d' % (hour, minute)) | |
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
func max(x, y int) int { | |
if x > y { | |
return x | |
} | |
return y | |
} | |
func replaceElements(arr []int) []int { | |
res := make([]int, len(arr)) |
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
func sumZero(n int) []int { | |
if n <= 0 { | |
return []int{} | |
} | |
res := make([]int, n) | |
for i := 0; i < n - 1; i++ { | |
res[i] = i | |
} | |
res[n-1] = - ((n - 2) * (n - 1) >> 1) | |
return res |
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
import "strings" | |
func wordPattern(pattern string, str string) bool { | |
var res1 [27]string | |
res2 := map[string]int{} | |
str_list := strings.Split(str, " ") | |
if len(str_list) != len(pattern) { | |
return false | |
} | |
for i := 0; i < len(pattern); i++ { |
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 longestWord(self, words: List[str]) -> str: | |
""" | |
:type words: List[str] | |
:rtype: str | |
""" | |
words.sort() | |
save = set() #用list存储的话,后面搜索会比较慢 | |
res = "" | |
for word in words: |
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. | |
* type TreeNode struct { | |
* Val int | |
* Left *TreeNode | |
* Right *TreeNode | |
* } | |
*/ | |
func minDepth(root *TreeNode) int { | |
if root == nil { |
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
func isalpha(c byte) bool { | |
return c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' | |
} | |
func toLower(c byte) byte { | |
if c >= 'A' && c <= 'Z' { | |
c += 'a' - 'A' | |
} | |
return c |
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
// Forward declaration of guess API. | |
// @param num, your guess | |
// @return -1 if my number is lower, 1 if my number is higher, otherwise return 0 | |
int guess(int num); | |
class Solution { | |
public: | |
int guessNumber(int n) { | |
int s = 1, e = n; | |
while (s < n) { |
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
func firstUniqChar(s string) int { | |
var cnt [26]int | |
for _, c := range s { | |
cnt[c-'a']++ | |
} | |
for i, c := range s { | |
if cnt[c-'a'] == 1 { | |
return i | |
} | |
} |
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
func max(x, y int) int { | |
if x > y { | |
return x | |
} | |
return y | |
} | |
func rob(nums []int) int { | |
if len(nums) == 0 { |
NewerOlder