分类
Develop Java 算法

Leetcode: Nested List Weight Sum II

Given a nested list of integers, return the sum of all […]

分类
Develop Java ruby on rails 算法

Leetcode: Factor Combinations

Numbers can be regarded as product of its factors. For […]

分类
Develop ruby on rails 算法

Leetcode: Binary Search

Given a sorted (in ascending order) integer array nums […]

分类
Develop ruby on rails 算法

Leetcode: Implement Trie (Prefix Tree)

Implement a trie with insert, search, and startsWith me […]

分类
Develop Java 算法

Leetcode: Min Stack

Design a stack that supports push, pop, top, and retrie […]

分类
C++ Develop 算法

Leetcode: Merge k Sorted Lists

Merge k sorted linked lists and return it as one sorted […]

分类
Develop ruby on rails 算法

Leetcode: Encode and Decode TinyURL

TinyURL is a URL shortening service where you enter a U […]

分类
C++ Develop 算法

Leetcode: LRU Cache

Design and implement a data structure for Least Recentl […]

分类
Develop 算法

Leetcode: Word Ladder II

Question Given two words (beginWord and endWord), and a […]

分类
C++ Develop ruby on rails 算法

Leetcode: Valid Number

Question Validate if a given string is numeric. Some ex […]

分类
C++ Develop 算法

Leetcode: Palindrome Number

Problem Leetcode link for this question Determine wheth […]

分类
C++ Develop 算法

Leetcode: String to Integer (atoi)

Problem Leetcode link Implement atoi to convert a strin […]

分类
C++ Develop 算法

Leetcode: Contains Duplicate II

Question Contains Duplicate II Given an array of intege […]

分类
Develop 算法

Leetcode: Integer to Roman

Question: Integer to Roman Given an integer, convert it […]

分类
Develop 算法

LeetCode: Reverse Integer

Previous Post This is the previous post on same questio […]

分类
Develop 算法

LeetCode: ZigZag Conversion

Previous post This is the old post on this question, us […]

分类
C++ Develop 算法

LeetCode Problem: Maximum Depth of Binary Tree

Recursively count the depth of tree node. One node&#821 […]

分类
C++ Develop 算法

LeetCode Problem: Valid Palindrome

To solving this problem, using two pointer to track the […]

分类
C++ Develop 算法

LeetCode Problem: Pascal’s Triangle II

Follow the algorithm in LeetCode Problem: Pascal’s Tria […]

分类
C++ Develop 算法

LeetCode Problem: Pascal’s Triangle

The problem is simple, each element in the triangle is […]

分类
C++ Develop 算法

LeetCode Problem: Populating Next Right Pointers in Each Node II

The code in the previous article LeetCode Problem: Popu […]

分类
C++ Develop 算法

LeetCode Problem: Populating Next Right Pointers in Each Node, Level traversal of binary tree

It’s easy to doing this by using a queue, doing a […]

分类
C++ Develop 算法

LeetCode Problem:Flatten Binary Tree to Linked List

We can notice that in the flattened tree, each sub node […]

分类
C++ Develop 算法

LeetCode Problem:Distinct Subsequences

(2013-1-5更新了动态规划版本,见下面) 这题有点复杂,一开始拿到都不知道怎么下手。 尝试的路径是: 1 […]

分类
C++ Develop 算法

LeetCode题目:Convert Sorted List to Binary Search Tree

问题比上一个难一点,如果是可以用O(n)空间的话,倒是可以开一个数组放上这n个数,然后按上一个问题的解法去做。 […]

分类
C++ Develop 算法

LeetCode题目:Convert Sorted Array to Binary Search Tree

对排序的数组进行二分查找样式的遍历就行了。 Convert Sorted Array to Binary Se […]

分类
C++ Develop 算法

LeetCode题目:Construct Binary Tree from Inorder and Postorder Traversal

这题和上一道题类似,也是首先在postorder中,最后那一个肯定是整棵树的根,然后在inorder中查找这个 […]

分类
C++ Develop 算法

LeetCode题目:Construct Binary Tree from Preorder and Inorder Traversal

这曾经是一道很难的题目,看来这一阵的锻炼确实是有效果的。 方法是,画一棵树出来,比如: 1 / \ 2 3 \ […]

分类
C++ Develop 算法

LeetCode题目:Binary Tree Zigzag Level Order Traversal

比较简单,广度优先变一下就可以了,用一个bool记录是从左到右还是从右到左,每一层结束就翻转一下。 Binar […]

分类
C++ Develop 算法

LeetCode题目:Binary Tree Maximum Path Sum

这道题好难,因为在一颗二叉树中有多种情况,这条最长的路径有可能是从某个中间节点直接到某个叶子节点的,也有可能是 […]

分类
C++ Develop 算法

LeetCode题目:Binary Tree Level Order Traversal II

和上一题差不多,只不过最后输出的时候颠倒一下,另外:std::list才有push_front(),而std: […]

分类
C++ Develop 算法

LeetCode题目:Binary Tree Level Order Traversal

题目简单,经典方法。只不过这题需要每一个level单独作为一个vector输出,因此在每一个level结束的时 […]

分类
C++ Develop 算法

LeetCode题目:Best Time to Buy and Sell Stock III,一维动态规划

和前两道题比起来的话,这道题最难了,因为限制了交易次数。 解决问题的途径我想出来的是:既然最多只能完成两笔交易 […]

分类
C++ Develop 算法

LeetCode题目:Best Time to Buy and Sell Stock II

这个更简单了,题目要求可以多次买卖,但是同一时间只能有一股在手里。 这样就可以在每次上升子序列之前买入,在上升 […]

分类
C++ Develop 算法

LeetCode题目:Best Time to Buy and Sell Stock

这个很简单,一次扫描完成。只需要找到最大增长即可。 从前往后,用当前价格减去此前最低价格,就是在当前点卖出股票 […]

分类
C++ Develop 算法

LeetCode题目:ZigZag Conversion

直观的算法,写一下不同行数下的例子就能找到规律了。 nRows = 2 0 2 4 6 … 1 3 5 7 […]

分类
C++ Develop 算法

LeetCode题目:Word Search,回溯

回溯来解。 在back部分需要增加一段,因为对于word中第一个字符的位置是随意的;后面字符必须和前一个字符匹 […]

分类
C++ Develop 算法

LeetCode题目:Wildcard Matching

这题有点困难。 一开始用很直观的递归算法:逐个看p字符串的字符,针对不同的可能性,’‘ […]

分类
C++ Develop 算法

LeetCode题目:Validate Binary Search Tree

就按照BST的要求进行递归,对于每一个子树,限制它的最大,最小值,如果超过则返回false。 对于根节点,最大 […]

分类
C++ Develop 算法

LeetCode题目:Valid Sudoku

神奇了,只检查了每行重复、每列重复和每9宫格重复就过了大测试集合。 难道只要满足每行、每列、每9宫格不重复的数 […]