随笔分类 -  LeetCodeOJ

摘要:class Solution(object): def removeOuterParentheses(self, S): """ :type S: str :rtype: str """ mark = 0 ret = '' for i in S: if i == '(': ... 阅读全文
posted @ 2019-04-08 09:25 miuc 阅读(169) 评论(0) 推荐(0)
摘要:不是很难的模拟题,想好前后状态的变化就会发现,其实“)”括号才可以抵消之前的“(”括号,反之不行。class Solution(object): def minAddToMakeValid(self, S): """ :type S: str :rtype: int """ l, r = 0, 0 for i... 阅读全文
posted @ 2019-03-27 09:02 miuc 阅读(109) 评论(0) 推荐(0)
摘要:递归题# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution(object): def pr... 阅读全文
posted @ 2019-03-18 09:23 miuc 阅读(140) 评论(0) 推荐(0)
摘要:感觉不是很难的题,控制一下变量和范围就OK了。class Solution(object): def diStringMatch(self, S): """ :type S: str :rtype: List[int] """ x1 = 10000 x2 = 10000 ret = [10000... 阅读全文
posted @ 2019-03-15 15:23 miuc 阅读(118) 评论(0) 推荐(0)
摘要:简单的字符串判断,水题开启新一天。class Solution(object): def findAndReplacePattern(self, words, pattern): """ :type words: List[str] :type pattern: str :rtype: List[str] """ ... 阅读全文
posted @ 2019-03-14 09:27 miuc 阅读(109) 评论(0) 推荐(0)
摘要:水一题弱题庆祝IBM MQ搭建成功。class Solution(object): def judgeCircle(self, moves): """ :type moves: str :rtype: bool """ result = [0, 0] for i in moves: fo... 阅读全文
posted @ 2019-03-13 15:48 miuc 阅读(156) 评论(0) 推荐(0)
摘要:树的转换,一道新题,部分递归的条件判断不是很清晰,WA了一次。# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass... 阅读全文
posted @ 2019-03-12 13:56 miuc 阅读(125) 评论(0) 推荐(0)
摘要:比较有意思的模拟题,花了点时间,主要是我没有认真读题模拟。。from collections import dequeclass Solution(object): def deckRevealedIncreasing(self, deck): """ :type deck: List[int] :rtype: List[int] ""... 阅读全文
posted @ 2019-03-11 14:06 miuc 阅读(110) 评论(0) 推荐(0)
摘要:比较简单的模拟题。#905class Solution(object): def sortArrayByParity(self, A): """ :type A: List[int] :rtype: List[int] """ ret = [] for i in A: if i % 2 ... 阅读全文
posted @ 2019-03-08 09:17 miuc 阅读(146) 评论(0) 推荐(0)
摘要:没错,我就是弱题收割机。select name, population, area from World where area > 3000000 or population > 25000000;class Solution(object): def sortedSquares(self, A): """ :type A: List[int] :r... 阅读全文
posted @ 2019-03-07 09:44 miuc 阅读(113) 评论(0) 推荐(0)
摘要:看描述就知道是一道搜索题,不过判断条件有点多,需要全部位置都踩一遍,相当于一笔画?代码其实有点潦草了,因为额外的有点工作的事情,最近时间可能不多了。class Solution(object): def checkPath(self, grid, n, m): for i in range(n): for j in range(m): ... 阅读全文
posted @ 2019-03-06 14:41 miuc 阅读(117) 评论(0) 推荐(0)
摘要:在2N长度的队列中查找重复了N次的元素,其他N个元素唯一。考虑了下是否可以只读前N+1个元素就推测出来,看来不行,那么目前可行的方案就只有先排序,再找规律了。class Solution(object): def repeatedNTimes(self, A): """ :type A: List[int] :rtype: int ""... 阅读全文
posted @ 2019-03-05 09:16 miuc 阅读(94) 评论(0) 推荐(0)
摘要:比较基础的二叉树排序树插入,写了个递归。# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution(o... 阅读全文
posted @ 2019-03-04 10:39 miuc 阅读(112) 评论(0) 推荐(0)
摘要:依旧不是难题,练手练手,这道题本来准备一次AC的,结果出现了两个笔误+一次读题错误,失败,还需要努力。class Solution(object): def uniqueMorseRepresentations(self, words): """ :type words: List[str] :rtype: int """ ... 阅读全文
posted @ 2019-03-01 09:37 miuc 阅读(80) 评论(0) 推荐(0)
摘要:比较简单的树拆分生成,我发现递归的思路我是比较有感觉的。。# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneimport ... 阅读全文
posted @ 2019-02-28 08:54 miuc 阅读(90) 评论(0) 推荐(0)
摘要:今天开始加快速度,趁着还有空多刷几题,语言换成python提高速度了。1. Unique Email Addresses弱题,注意@符号前后的处理方式不同class Solution(object): def numUniqueEmails(self, emails): """ :type emails: List[str] :rtype: int ... 阅读全文
posted @ 2019-02-26 15:06 miuc 阅读(211) 评论(0) 推荐(0)
摘要:binary search tree (BST) 二分树的基本方法,search,insert,MAX,MIN,delete概念复习下,这道题简单的递归搜索可以解决。/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *rig... 阅读全文
posted @ 2019-02-25 09:22 miuc 阅读(203) 评论(0) 推荐(0)
摘要:不是很难的题,O(n^2)解决。主要的思路是确定你需要的信息,和状态转移方程。我们需要确定各个行列最大的高度:row[i], column[j],然后取 min(row[i], column[j]) - grid[i][j] 之和就可以了。class Solution {public: int maxIncreaseKeepingSkyline(vector>& grid) { ... 阅读全文
posted @ 2019-02-22 09:40 miuc 阅读(162) 评论(0) 推荐(0)
摘要:间隔2天,继续开始写LeetCodeOj。 原题: Maximum Subarray 其实这题很早就看了,也知道怎么做,在《编程珠玑》中有提到,求最大连续子序列,其实只需要O(n)的复杂度就可以。 今天早上到公司比较早,就写了一下,发现还是有地方忘了: 1. 记得记录当前的最大值,因为局部最大和全局最大是不同的。 2. 记得描述32位int最大值,最小值的方法,最大值是 0x7FFFFF... 阅读全文
posted @ 2014-03-07 13:24 miuc 阅读(182) 评论(0) 推荐(0)
摘要:原题 Climbing Stairs 求斐波那契数列的第N项,开始想用通项公式求解,其实一个O(n)就搞定了。 class Solution {public: int climbStairs(int n) { if (n==0) return 0; int n1 = 0; int n2 = 1; ... 阅读全文
posted @ 2014-03-03 20:19 miuc 阅读(142) 评论(0) 推荐(0)