leetcode 【LeetCode】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,
leetcode 【LeetCode】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. 求树的深度 代码
leetcode 【LeetCode】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,
leetcode 【LeetCode】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
leetcode 【LeetCode】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
leetcode 【LeetCode】88. 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
leetcode 【LeetCode】83. 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->
leetcode 【LeetCode】70. 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
leetcode 【LeetCode】67. Add Binary 问题描述 Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". 二进制加法 代码 class Solution { public: string addBinary(string a, string b) { int cur=
leetcode 【LeetCode】66. 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.
leetcode 58. Length of Last Word 问题描述 Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word does not exist, return
leetcode 38. Count and Say 问题描述 The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, ... 1 is read off as "one 1" or 11. 11 is read off as "two 1s"
leetcode 36. Valid Sudoku 问题描述 Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules [http://sudoku.com.au/TheRules.aspx]. The Sudoku board could be partially filled, where empty cells are filled with
leetcode 【LeetCode】24. Swap Nodes in Pairs 问题描述 Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm
leetcode 【LeetCode】27. Remove Element 问题描述 Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this in
leetcode 【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. 合并两个已排好序的数组 代码 #include using namespace
leetcode 【Leetcode】 问题描述 Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in
leetcode 【Leetcode】Roman to Integer 问题描述 Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 罗马数字转数字,如VII=7 只要了解规则 [http://baike.baidu.com/link?url=x4oib22b_
leetcode 【Leetcode】Palindrome Number 问题描述 Determine whether an integer is a palindrome. Do this without extra space. Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, note the restriction
leetcode 【LeetCode】String to Integer (atoi) 问题描述 Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the
leetcode 【LeetCode】7. Reverse Integer 问题描述 Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 问题分析 题目不难,稍微麻烦的是整型溢出。比如1234567899,倒过来是9987654321,但现在已经超出了整型的最大数了,所以,针对整型溢出需要做一定处理。 代码 class Solution { public: int reverse(int x) { int
leetcode 【LeetCode】5. Longest Palindromic Substring 问题描述 Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. 给定一个字符串S,找到最长的回文子串(
leetcode 【LeetCode】Longest Substring Without Repeating Characters 问题描述 Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer is "b", with
leetcode 【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
leetcode 【Leetcode】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: