随笔分类 -  leetcode

share my thought on leetcode
摘要:小易邀请你玩一个数字游戏,小易给你一系列的整数。你们俩使用这些整数玩游戏。每次小易会任意说一个数字出来,然后你需要从这一系列数字中选取一部分出来让它们的和等于小易所说的数字。 例如: 如果{2,1,2,7}是你有的一系列数,小易说的数字是11.你可以得到方案2+2+7 = 11.如果顽皮的小易想坑你 阅读全文
posted @ 2016-08-12 20:35 NeilZhang 阅读(523) 评论(0) 推荐(0)
摘要:Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: All root-to-leaf paths are: 思路:用两个stack<TreeNode*> i 阅读全文
posted @ 2016-08-03 18:57 NeilZhang 阅读(257) 评论(0) 推荐(0)
摘要:小明陪小红去看钻石,他们从一堆钻石中随机抽取两颗并比较她们的重量。这些钻石的重量各不相同。在他们们比较了一段时间后,它们看中了两颗钻石g1和g2。现在请你根据之前比较的信息判断这两颗钻石的哪颗更重。 给定两颗钻石的编号g1,g2,编号从1开始,同时给定关系数组vector,其中元素为一些二元组,第一 阅读全文
posted @ 2016-08-01 14:41 NeilZhang 阅读(831) 评论(0) 推荐(0)
摘要:Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured by flipping all 'O's into 'X's in that surrounded 阅读全文
posted @ 2016-05-31 19:09 NeilZhang 阅读(266) 评论(0) 推荐(0)
摘要:Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, 阅读全文
posted @ 2016-05-30 20:42 NeilZhang 阅读(238) 评论(0) 推荐(0)
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode*... 阅读全文
posted @ 2016-05-20 19:43 NeilZhang 阅读(241) 评论(0) 推荐(0)
摘要:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. 通过一个p指针,遍历 二叉树,并将每次的值 保存在 sum2 中 。 遇到右节点,将右节点+d 阅读全文
posted @ 2016-05-16 20:48 NeilZhang 阅读(261) 评论(0) 推荐(0)
摘要:不能通过 当元素中 有 val == INT_MAX 或者 val == INT_MIN 阅读全文
posted @ 2016-05-16 14:09 NeilZhang 阅读(212) 评论(0) 推荐(0)
摘要:Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example,Given n = 3, there are a total of 5 unique BST' 阅读全文
posted @ 2016-04-02 15:47 NeilZhang 阅读(242) 评论(0) 推荐(0)
摘要:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy 阅读全文
posted @ 2016-04-01 13:43 NeilZhang 阅读(286) 评论(0) 推荐(0)
摘要:Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have ex 阅读全文
posted @ 2016-04-01 10:24 NeilZhang 阅读(175) 评论(0) 推荐(0)
摘要:introduction: Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary repres 阅读全文
posted @ 2016-03-31 13:00 NeilZhang 阅读(275) 评论(0) 推荐(0)