Skip to content

Instantly share code, notes, and snippets.

View luoheng23's full-sized avatar

luoheng luoheng23

View GitHub Profile
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))
func max(x, y int) int {
if x > y {
return x
}
return y
}
func replaceElements(arr []int) []int {
res := make([]int, len(arr))
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
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++ {
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:
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func minDepth(root *TreeNode) int {
if root == nil {
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
// 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) {
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
}
}
func max(x, y int) int {
if x > y {
return x
}
return y
}
func rob(nums []int) int {
if len(nums) == 0 {