leetcode
ttgump
这个作者很懒,什么都没留下…
展开
-
Leetcode: Balanced Binary Tree
从今天起逐渐把我做过的leetcode题目放上来。 Balanced Binary Tree Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate e原创 2014-04-03 03:57:47 · 437 阅读 · 0 评论 -
LeetCode: Permutation Sequence
/* The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3): "123" "132" "2原创 2014-04-26 14:36:51 · 490 阅读 · 0 评论 -
LeetCode: Add Binary
Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". 这个题目直接用原创 2014-04-26 14:39:44 · 356 阅读 · 0 评论 -
LeetCode: Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from th原创 2014-04-08 01:43:40 · 479 阅读 · 0 评论 -
LeetCode: Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given [100, 4, 200, 1, 3, 2], The longest consecutive elements sequence is [1, 2,原创 2014-04-08 01:40:47 · 452 阅读 · 0 评论 -
LeetCode: Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321原创 2014-04-08 01:46:05 · 451 阅读 · 0 评论 -
LeetCode: Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. 使用ha'sh原创 2014-04-08 01:51:08 · 902 阅读 · 0 评论 -
LeetCode: Linked List Cycle
Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Follow up: Can you solve it without using extra space?原创 2014-04-05 13:53:07 · 280 阅读 · 0 评论 -
Leetcode: Binary_Tree_Postorder_Traversal
/* Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [3,2,1]. Note: Recursive so原创 2014-04-05 13:42:19 · 384 阅读 · 0 评论 -
LeetCode: Merge two sorted linked lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.原创 2014-04-05 14:42:28 · 458 阅读 · 0 评论 -
LeetCode: Remove Duplicates from Sorted List
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place wi原创 2014-04-05 14:35:14 · 307 阅读 · 0 评论 -
LeetCode: Linked_List_Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Follow up: Can you solve it without using extra space?原创 2014-04-05 13:54:39 · 365 阅读 · 0 评论 -
Leetcode: Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 此题用递归的方法,首先找到数组中的中值作为root,之后把中值左边的和右边的数组作为新数组分别做递归。 /** * Definition for binary tree * publi原创 2014-04-05 13:50:36 · 340 阅读 · 0 评论 -
Leetcode: Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,2,3]. Note: Recursive solutio原创 2014-04-05 13:48:17 · 349 阅读 · 0 评论 -
Leetcode: Copy List with Random Pointer
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 of the list. 此处分析参考了http://mp.weixin.qq.com/mp/原创 2014-04-03 04:03:27 · 494 阅读 · 0 评论 -
LeetCode: Add Two Numbers
/* You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a原创 2014-04-26 14:42:45 · 533 阅读 · 0 评论