- 博客(7)
- 收藏
- 关注
原创 https://www.nowcoder.com/practice/5427af99168b45f4a14aec195b28a839?tpId=98&&tqId=32999&rp=1&ru=/acti
#include<cstdio> #include<cmath> #include<algorithm> #define maxn 100020 #define maxm 200020 using namespace std; int tot = 0, n; int fir[maxn], en[maxm], nex[maxm]; int f[maxn][2...
2019-10-18 23:50:16 6347 5
原创 1023. Camelcase Matching
要达到题目的要求: query 中的 word 能否通过对 pattern 添加小写字母得到。 分为两个步骤去判断是否成立: 1. word 中 应包含这个 pattern 子串 2. 如果只能通过添加小写字母得到,那么 word 和 pattern 中的大写字母应该一样 题解中的: class Solution: def camelMatch(self, queri...
2019-10-10 09:33:16 126
原创 421. Maximum XOR of Two Numbers in an Array
https://leetcode-cn.com/problems/maximum-xor-of-two-numbers-in-an-array/solution/li-yong-yi-huo-yun-suan-de-xing-zhi-tan-xin-suan-f/ 两个数相同位置上1、0不同的位数越多,且越靠近高位,最后的结果越大 1. 异或运算就是二进制下不应用进位的加法 2. 如果...
2019-10-09 15:16:36 121
原创 208. Implement Trie (Prefix Tree)
accetped : import numpy as np class Trie(object): def __init__(self): """ Initialize your data structure here. """ self.k = 1 self.record = np.zeros((100...
2019-10-09 14:26:34 84
原创 149. Max Points on a Line
题解里的高赞答案:可以运行通过 from collections import * class Solution: def maxPoints(self, points: List[List[int]]) -> int: def calc(points, i): # defaultdict是collections里的一个类,就是带有默认值...
2019-10-08 18:01:22 116
原创 8. String to Integer (atoi)
题解中的最高赞答案: re.findall() 正则表达式用法 星号 * :解包作用 lstrip 方法: 自己根据题解的实现: ( python2 也是可以实现的 ) class Solution(object): def myAtoi(self, str): """ :type str: str :rtype:...
2019-10-07 23:36:46 91
原创 15. 3Sum
三个数的和为0,固定第一个数,然后用双指针。 思路: 双指针需要先对数组排序,固定最小的数(下标为k),指针 i 在 k → len(nums),指针 j 在 len(nums)- 1 → i, 1. nums[ k ] > 0 直接 break 跳出 2. k > 0 并且 nums[ k ] == nums[ k - 1 ] 就跳过 nums[ k ], 因为已经把包含 n...
2019-10-07 23:08:55 70
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人