LeetCode OJ--4Sum *】的更多相关文章

博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-Solution/ ———————————————————————————————————————— ———————————————————————————————————————— LeetCode OJ 题解 LeetCode OJ is a platform for preparing tech…
Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 = "aabcc", s2 = "dbbca", When s3 = "aadbbcbcac", return t…
Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reverse the string word by word. For example, Given s = "the sky is blue", return "blue is sky the". LeetCode OJ supports Python now! The s…
一直没有系统地学习过算法,不过算法确实是需要系统学习的.大二上学期,在导师的建议下开始学习数据结构,零零散散的一学期,有了链表.栈.队列.树.图等的概念.又看了下那几个经典的算法——贪心算法.分治算法.动态规划以及回溯算法.不过,都是知其一不知其二的一知半解.到最后,发现学到了一堆的一知半解,在学校课程开这门课时,却又是不得不再学一遍.学一样东西,又不全心全意地主动去把它学好,到最后只是花费了时间,却没真真学到东西.所以,不求学识有多广,但求所学的都精. 一个偶然的机会,让我在网上找到了一本社区…
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another comput…
常泡LC的朋友知道LC是不提供代码打包下载的,不像一般的OJ,可是我不备份代码就感觉不舒服- 其实我想说的是- 我自己写了抓取个人提交代码的小工具,放在GitCafe上了- 不知道大家有没有兴趣 https://gitcafe.com/aaronzhou/ ... ssion 拿Java写的,也打了一个包,本地有JRE环境就能运行,欢迎拍砖 抓取 LeetCode OJ 个人提交的代码 Gradle 构建项目 HttpClient.jsoup 抓取.解析网页 使用说明 进入release文件夹…
题目: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area. For example, given the following matrix: 1 0 1 0 0 1 0 1 1 1 1 1 0 0 1 0 Return 4. 题目链接:https://leetcode.com/problems/maximal-square…
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 给定一个整数,将他转换到罗马字符.同样这里的罗马字符不会超过1000(M),PS:关于罗马字符的介绍看我的这篇文章 :LeetCode OJ:Roman to Integer(转换罗马字符到整数) 这里的大体思路是这样的,例如对于罗马字符952来说,起答题的可以分成三个组成部分, 就…
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another comput…
Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero. To make problem a bit easier, all A, B, C, D have same length of N where 0 ≤ N ≤ 500. All integers are in the r…
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note: Elements in a quadruplet (a,b,c,d) must be in non-descending order.…
Valid Palindrome吐槽一下Leetcode上各种不定义标准的输入输出(只是面试时起码能够问一下输入输出格式...),此篇文章不是详细的题解,是自己刷LeetCode的一个笔记吧,尽管没有代码,可是略微难一点的都会标出主要思路,便于以后复习 PS:题目中有"水题"两字的都是一遍AC,没有标注的都说明了问题,顺序依照Leetcode上时间倒序排列,少量题目因为和之前的题目有相关性,因此将其放在一起,比方12题和13题,因此中间可能会"缺少"几道题目,缺少的…
Problem Link: https://oj.leetcode.com/problems/validate-binary-search-tree/ We inorder-traverse the tree, and for each node we check if current_node.val > prev_node.val. The code is as follows. # Definition for a binary tree node # class TreeNode: #…
Problem Link: https://oj.leetcode.com/problems/recover-binary-search-tree/ We know that the inorder traversal of a binary search tree should be a sorted array. Therefore, we can compare each node with its previous node in the inorder to find the two…
Problem Link: https://oj.leetcode.com/problems/same-tree/ The following recursive version is accepted but the iterative one is not accepted... # Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self.left =…
Problem Link: https://oj.leetcode.com/problems/symmetric-tree/ To solve the problem, we can traverse the tree level by level. For each level, we construct an array of values of the length 2^depth, and check if this array is symmetric. The tree is sym…
Problem Link: https://oj.leetcode.com/problems/binary-tree-level-order-traversal/ Traverse the tree level by level using BFS method. # Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # se…
Problem Link: https://oj.leetcode.com/problems/binary-tree-zigzag-level-order-traversal/ Just BFS from the root and for each level insert a list of values into the result. # Definition for a binary tree node # class TreeNode: # def __init__(self, x):…
Problem Link: https://oj.leetcode.com/problems/maximum-depth-of-binary-tree/ Simply BFS from root and count the number of levels. The code is as follows. # Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x #…
Problem Link: https://oj.leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/ The basic idea is same to that for Construct Binary Tree from Inorder and Postorder Traversal. We solve it using a recursive function. First, we…
Problem Link: https://oj.leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/ This problem can be easily solved using recursive method. By given the inorder and postorder lists of the tree, i.e. inorder[1..n] and postorde…
Problem Link: https://oj.leetcode.com/problems/binary-tree-level-order-traversal-ii/ Use BFS from the tree root to traverse the tree level by level. The python code is as follows. # Definition for a binary tree node # class TreeNode: # def __init__(s…
Problem Link: http://oj.leetcode.com/problems/convert-sorted-array-to-binary-search-tree/ Same idea to Convert Sorted Array to Binary Search Tree, but we use a recursive function to construct the binary search tree. # Definition for a binary tree nod…
Problem Link: http://oj.leetcode.com/problems/convert-sorted-list-to-binary-search-tree/ We design a auxilar function that convert a linked list to a node with following properties: The node is the mid-node of the linked list. The node's left child i…
Problem Link: http://oj.leetcode.com/problems/balanced-binary-tree/ We use a recursive auxilar function to determine whether a sub-tree is balanced, if the tree is balanced, it also return the depth of the sub-tree. A tree T is balanced if the follow…
Problem Link: http://oj.leetcode.com/problems/minimum-depth-of-binary-tree/ To find the minimum depth, we BFS from the root and record the depth. For each level we add 1 to the depth and return the depth value when we reach a leaf. The python code is…
Problem Link: http://oj.leetcode.com/problems/path-sum-ii/ The basic idea here is same to that of Path Sum. However, since the problem is asking for all possible root-to-leaf paths, so we should use BFS but not DFS. The python code is as follows. # D…
Problem Link: http://oj.leetcode.com/problems/path-sum/ One solution is to BFS the tree from the root, and for each leaf we check if the path sum equals to the given sum value. The code is as follows. # Definition for a binary tree node # class TreeN…
Problem Link: http://oj.leetcode.com/problems/flatten-binary-tree-to-linked-list/ The problem is asking for flatterning a binary tree to linked list by the pre-order, therefore we could flatten tree from the root. For each node, we link it with its n…
Problem Link: http://oj.leetcode.com/problems/distinct-subsequences/ A classic problem using Dynamic Programming technique. Let m and n be the length of the strings T and S. Let R[i][j] be the count of distinct subsequence of T[0..i] in S[0..j]. Obvi…