LeetCode 371. Sum of Two Integers

这一题是不准用+-*/来计算两个整数之和。 很容易想到是用位运算来做。 a和b之和包括两个部分,一个部分是a或b在某一位上有一个为1,这部分可以

Leetcode Weekly Contest 77

804. Unique Morse Code Words 用一个set来保存转成摩斯码的结果然后返回set大小即可。 class Solution: def uniqueMorseRepresentations(self, words): trans = set() alp = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] for w in words: trans.add(''.join(alp[ord(c)-ord('a')] for c in w)) return len(trans) 807. Max Increase to Keep City Skyline 计算每一列每一

LeetCode 300. Longest Increasing Subsequence

674. Longest Continuous Increasing Subsequence 与 LeetCode 300. Longest Increasing Subsequence 是两道递增子串的问题。 LeetCode 674. Longest Continuous Increasing Subsequence 这一题是一题简单题,只需要在每一个位置判断是否破坏了递增,破坏了则从长度为1开始重来

LeetCode 743. Network Delay Time

这题是一道用BFS或者DFS就可以解决的问题。 直接上暴力DFS的代码代码: class Solution: def networkDelayTime(self, times, N, K): """ :type times: List[List[int]] :type N: int :type K: int :rtype: int """ visited = {} l = [(K, 0)] # dic[i

LeetCode 295. Find Median from Data Stream

此题295. Find Median from Data Stream 与480. Sliding Window Median 类似。都是在一个变化的序列中多次求中位数,而我们知道中位数与大小相关,所以很容易想到用堆来维护。 但对于

LeetCode 136. Single Number

Single Number I 题目链接:136. Single Number 一个数组所有数字都包含两次,除了一个数字包含一次,要找出这个数字非常容易。 最简单的方法是使用一个counterM

Leetcode Weekly Contest 76

800. Similar RGB Color 这题很容易,只需要将其分为3个部分,对每个部分找个最相近的 ‘XX’ 格式的值即可。 对,每一个 ‘XY’ 值,最近的一定在 ‘XX’, ‘(X-1)(X-1)’, ‘(X+1)(X+1)’ 之中,所以我们计算出这三

LeetCode 42: Trapping Rain Water I & II

本篇包括42.Trapping Rain Water and 407.Trapping Rain Water II. Trapping Rain Water This problem is taged with “Two Pointers” and “Stack”, they corresponds to two different solutions. 这道题目带有“双指针”和“栈”这两个标签,对应这道题的两种解