- 博客(58)
- 资源 (3)
- 收藏
- 关注
原创 LeetCode——Populating Next Right Pointers in Each Node
题目:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If there
2015-07-19 16:04:26
434
1
原创 LeetCode——Insertion Sort List
题目:Sort a linked list using insertion sort.解答:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * };
2015-07-18 23:08:40
390
原创 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 / 3return [1,2,3].解答:/** * Definition for a binary tree n
2015-07-18 00:31:14
420
原创 LeetCode——Evaluate Reverse Polish Notation
题目:Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1", "+", "3", "*
2015-07-08 23:15:55
305
原创 LeetCode——Find Minimum in Rotated Sorted Array
题目:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.You may assume no duplicate exists in the array.解答
2015-07-08 20:07:07
321
原创 LeetCode——Container With Most Water
题目:Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two
2015-06-28 00:59:22
275
原创 LeetCode——Summary Ranges
题目: Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return [“0->2”,”4->5”,”7”].解答:class Solution {public: string numToStr(int n
2015-06-27 20:24:33
398
原创 LeetCode——Same Tree
题目: Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.解答:/** * Defi
2015-06-24 23:18:51
337
原创 LeetCode——Merge Sorted Array
题目:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additio
2015-06-24 23:13:12
364
原创 LeetCode——Symmetric Tree
题目:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the following is n
2015-06-23 23:31:28
291
原创 LeetCode——Binary Tree Level Order Traversal II
题目: Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).For example: Given binary tree {3,9,20,#,#,15,7},
2015-06-23 22:46:47
354
原创 iOS Crash相关转载
iOS Crash文件的解析(一) 本文介绍了:1. Crash文件结构(Process Information(进程信息)、Basic Information、Exception、Thread Backtrace、Thread State、Binary Images)2. 常见的Crash类型(Watchdog timeout、User force-quit、Low Memory termin
2015-06-22 22:58:44
471
原创 LeetCode——Plus One
题目:Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.解答:class Solution {public
2015-06-22 01:07:12
363
原创 LeetCode——Climbing Stairs
题目:You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?解答:class Solution {public: in
2015-06-22 00:22:07
301
原创 LeetCode——Binary Tree Level Order Traversal
题目: Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).For example: Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20 / \
2015-06-22 00:10:21
342
原创 LeetCode——Balanced Binary Tree
题目: Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe
2015-06-21 13:26:29
267
原创 LeetCode——Minimum Depth of Binary Tree
题目: Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.解答:/** * Definition for a binary tree
2015-06-18 13:34:04
299
原创 LeetCode——Path Sum
题目:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example: Given the below binary tree and sum
2015-06-17 23:39:41
260
原创 LeetCode——Remove Duplicates from Sorted List
题目:Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.解答:/** * Definition for singly-
2015-06-17 23:22:02
251
原创 LeetCode——Remove Duplicates from Sorted Array
题目: 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 with
2015-06-17 13:26:32
239
原创 LeetCode——Valid Palindrome
题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example, “A man, a plan, a canal: Panama” is a palindrome. “race a car” is not a
2015-06-16 22:15:39
278
原创 LeetCode——Min Stack
题目: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) – Push element x onto stack. pop() – Removes the element on top of the stack. top() – Get
2015-06-16 21:48:01
259
原创 LeetCode——Merge Two Sorted 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.解答:/** * Definition for singly-linked list. * struct
2015-06-16 13:43:32
288
原创 LeetCode——Intersection of Two Linked Lists
题目: Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘
2015-06-15 23:36:43
326
原创 LeetCode——Majority Element
题目: Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element al
2015-06-15 21:25:24
304
原创 LeetCode——Factorial Trailing Zeroes
题目: Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.解答:class Solution {public: int trailingZeroes(int n) { int
2015-06-15 19:39:09
492
原创 LeetCode——Rotate Array
题目: Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].解答:class Solution {public: void reverse(int l,
2015-06-13 23:08:31
299
原创 LeetCode——House Robber
题目: You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent h
2015-06-13 13:23:18
279
原创 LeetCode——Invert Binary Tree
题目: Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1解答:/** * Definition for a binary tree node. * struct TreeNode { * int
2015-06-12 23:45:56
337
原创 LeetCode——Happy Number
题目: Write an algorithm to determine if a number is “happy”.A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares
2015-06-12 23:32:50
417
原创 LeetCode——Remove Linked List Elements
题目: Remove all elements from a linked list of integers that have value val.Example Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6 Return: 1 –> 2 –> 3 –> 4 –> 5解答:/** * Definition for singly-linked
2015-06-09 22:16:44
310
原创 LeetCode——Palindrome Number
题目: Determine whether an integer is a palindrome. Do this without extra space.解答://调优后的算法表现还不是很好,不知道还有没有更好的算法,暂时就这样吧!//11506 / 11506 test cases passed.//Status: Accepted//Runtime: 56 msclass Soluti
2015-06-09 21:55:36
304
原创 LeetCode——Reverse Integer
题目: Reverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321解答:class Solution {public: int reverse(int x) { int k = x < 0 ? -1 : 1; int abs = x *
2015-06-09 10:17:17
320
原创 LeetCode——Rectangle Area
题目:Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the total area is
2015-06-08 21:25:58
370
原创 iOS常见编码规范指引
参考文档:Coding Guidelines for Cocoa Google Objective-C Style Guide 中文版 [Cocoa]苹果 Cocoa 编码规范(白云飘飘博客)1留白和空格1.1空格 vs. 制表符Tip只使用空格,且一次缩进两个空格。我们使用空格缩进。不要在代码中使用制表符。你应该将编辑器设置成自动将制表符替换成空格。1.2行宽尽量让你的代码保持在 120
2015-06-08 15:54:48
604
原创 LeetCode——Maximum Depth of Binary Tree
题目:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.解答:/** * Definition for a binary tree n
2015-06-08 11:17:02
398
原创 LeetCode——Isomorphic Strings
题目:Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with another ch
2015-06-07 23:56:11
344
原创 LeetCode——Reverse Linked List
题目:Reverse a singly linked list.解答:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class S
2015-06-07 23:14:07
410
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人