- 博客(19)
- 收藏
- 关注
原创 107. 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,null,null,1
2016-11-24 19:15:48 137
原创 102. 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,null,null,15,7], 3 / \
2016-11-24 18:44:44 165
转载 leetcode难度及频率
轉載自:http://blog.csdn.net/yutianzuijin/article/details/11477603/ 1 Two Sum 2 5 array sort
2016-11-24 14:00:50 272
原创 100. 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. 思路:這題也沒什麼好
2016-11-21 18:22:43 167
原创 104. 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. 思路:這題本來要用DFS解的,寫著寫著不知道為啥用了backtrac
2016-11-21 18:20:19 123
原创 404. Sum of Left Leaves
Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24
2016-11-19 01:30:04 131
原创 112. 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
2016-11-19 01:08:30 156
原创 189. 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]. 思路:就用三部反轉法, 把原數據切兩分 1,
2016-11-18 17:12:48 160
原创 101. Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3
2016-11-18 13:10:49 192
原创 412. Fizz Buzz
Write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”.
2016-11-10 02:13:06 147
原创 20. Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are all va
2016-11-07 00:10:45 160
原创 9. Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space. 思路:就是用 "Reverse Integer" 的解法來判斷就行了 class Solution { public: bool isPalindrome(int x) { if( x < 0) return fa
2016-11-05 23:14:26 136
原创 136. Single Number
Given an array of integers, every element appears twice except for one. Find that single one. 思路:所有數 XOR起來,剩下的就是孤單的那一個了 class Solution { public: int singleNumber(vector& nums) {
2016-11-04 18:38:03 155
原创 371. Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example: Given a = 1 and b = 2, return 3. 思路:看來就用bit運算式 (a&b) a^b 就是不進位的狀態 就一直loop 去計算
2016-11-04 17:58:50 128
原创 191. Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). For example, the 32-bit integer ’11' has binary representation 00000000
2016-11-04 15:57:28 229
原创 7. Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 思路:就簡單用 x%10 一直拿個位數字,x/10一直消去個位數字 這邊記得檢查overflow,reject好幾次都是因為overflow沒回傳0 @_@ class Solut
2016-11-04 12:58:06 143
原创 1. Two Sum
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 exactly one solution. Example: Given nu
2016-11-04 00:05:47 227
原创 22. Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()
2016-08-23 00:47:55 205
原创 357. Count Numbers with Unique Digits
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x n. Example: Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x [11,22,33,44,
2016-08-23 00:41:54 211
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人