随笔分类 -  LeetCode

上一页 1 ··· 3 4 5 6 7
摘要:算法不扎实: 1. Minimum Absolute Difference in BST 我一开始的想法是递归的计算和当前结点的左右子结点的值的difference,发现是没有理解题意,题目中说的是任意的两个结点的差的绝对值,而不是相连的结点。特别坑的是,因为是BST,那么就会存在根结点的左子树的最 阅读全文
posted @ 2017-08-05 15:44 banananana 阅读(188) 评论(0) 推荐(0)
摘要:Python不熟悉 1. Reverse Words in a String III 这道题目我做出来了,但是我使用C语言的思想去做的,但是Python提供了reverse和map函数都可以实现; 我的实现: def reverseWords(s): """ :type s: str :rtype: 阅读全文
posted @ 2017-08-05 15:41 banananana 阅读(313) 评论(0) 推荐(0)
摘要:Python不熟悉 不同的做法 404. Sum of Left Leaves 这是我的做法,AC。 class Solution(object): res = 0 def recursive(self, root): if root == None: return if root.left != 阅读全文
posted @ 2017-08-05 15:39 banananana 阅读(270) 评论(0) 推荐(0)
摘要:6. Wildcard Matching 题目 Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character.'*' Matches any sequence of 阅读全文
posted @ 2017-07-15 15:24 banananana 阅读(740) 评论(0) 推荐(0)
摘要:题目 "题目" Think about Zuma Game. You have a row of balls on the table, colored red(R), yellow(Y), blue(B), green(G), and white(W). You also have several 阅读全文
posted @ 2017-04-01 06:27 banananana 阅读(472) 评论(0) 推荐(0)
摘要:题目 "题目" 大概意思是根据指定的格式将字符串进行展开 思路 递归的思路 递归计算出括号最里面的字符串,依次再处理外面一层的字符串,每个单元内的字符串类似于一个结点,个数则为结点的个数。父结点则是将这些个数的字符串组合在一起,以此类推到跟结点,就是我们要求的结果。 迭代的思路 用两个栈来分别保存下 阅读全文
posted @ 2017-03-24 16:52 banananana 阅读(360) 评论(0) 推荐(0)
摘要:题目 "题目" 思路 一看就是单点更新和区间求和,故用线段树做。 一开始没搞清楚,题目给定的i是从0开始还是从1开始,还以为是从1开始,导致后面把下标都改掉了,还有用区间更新的代码去实现单点更新,虽然两者思路是一样的,但是导致TLE,因为区间会把所有都递归一遍,加了个判断,就ok了。 cpp if 阅读全文
posted @ 2017-03-23 15:14 banananana 阅读(138) 评论(0) 推荐(0)
摘要:题意 "题目" 思路 一开始想用双向广搜来做,找他们相碰的点,但是发现对其的理解还是不够完全,导致没写成功。不过,后来想清楚了,之前的错误可能在于从边界点进行BFS,其访问顺序应该是找到下一个比当前那个要大的点,但是我写反了。。可以先对左边的队列进行BFS,保存其visited,再接着对右边的队列进 阅读全文
posted @ 2017-03-22 15:53 banananana 阅读(231) 评论(0) 推荐(0)
摘要:题意 "题目" 思路 我一开始的时候想的是最简单的方法,就是遍历所有的值为1的元素,再根据其为起点进行BFS,计算层数,但是这个方法超时了; 其实,可以不用从1开始遍历,从0开始遍历,找到和值为1相邻的0,将其的层数设置为1就行了,为什么可以不用从1开始,因为并没有要求从规定的起点到指定的位置,计算 阅读全文
posted @ 2017-03-22 00:11 banananana 阅读(532) 评论(0) 推荐(0)
摘要:题意 "题目" 思路 我一开始想的时候只考虑到一个结点周围的边界的情况,并没有考虑到边界的高度其实影响到所有的结点盛水的高度。 我们可以发现,中间是否能够盛水取决于边界是否足够高于里面的高度,所以这必然是一个从外到内,从小到大的一个过程。因为优先队列必然首先访问的是边界中最小的高度,如果周围小于这个 阅读全文
posted @ 2017-03-21 09:39 banananana 阅读(257) 评论(0) 推荐(0)
摘要:前言 之前把一些LeetCode里面的题目的思路写在了本子上,现在把这些全都放到博客上,以后翻阅比较方便。 题目 99.Recover Binary Search Tree 题意 Two elements of a binary search tree (BST) are swapped by mi 阅读全文
posted @ 2017-03-10 08:30 banananana 阅读(853) 评论(0) 推荐(0)
摘要:前言 这道题的实现方法有很多,包括dp,贪心算法,二分搜索,普通实现等等。 题目 Given a string s and a string t, check if s is subsequence of t. You may assume that there is only lower case 阅读全文
posted @ 2017-03-07 06:47 banananana 阅读(374) 评论(0) 推荐(0)
摘要:题意 Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, ret 阅读全文
posted @ 2017-02-15 06:26 banananana 阅读(298) 评论(0) 推荐(0)
摘要:题意 Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results. Note: The input string may c 阅读全文
posted @ 2017-02-15 06:24 banananana 阅读(308) 评论(0) 推荐(0)
摘要:title: word ladder总结 categories: LeetCode tags: 算法 LeetCode comments: true date: 2016 10 16 09:42:30 题意 Given two words (beginWord and endWord), and a 阅读全文
posted @ 2017-02-15 06:17 banananana 阅读(502) 评论(0) 推荐(0)
摘要:题意 Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. 意思就是说在给定的节点中计算出在同一条直线上的最大节点个数。 思路 这道题,题意很容易理解,但 阅读全文
posted @ 2017-02-08 07:33 banananana 阅读(349) 评论(0) 推荐(0)
摘要:题意 Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, ret 阅读全文
posted @ 2017-01-17 06:59 banananana 阅读(250) 评论(0) 推荐(0)
摘要:题意 Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) Get th 阅读全文
posted @ 2017-01-15 18:31 banananana 阅读(290) 评论(0) 推荐(0)
摘要:题意 You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a co 阅读全文
posted @ 2017-01-11 07:26 banananana 阅读(233) 评论(0) 推荐(0)

上一页 1 ··· 3 4 5 6 7