题目: 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) { std::string result; std::string::reverse_iter…
题目: 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 = 22, 5 / \ 4 8 / / \ 11 13 4 / \ \ 7 2 1 return…
题目: 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 3 But the following is not: 1 / \ 2 2 \ \ 3 3 Note:Bonus points if you could solve…
题目: 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. 代码: /** * Definition for a binary tree node. * struct TreeNode…
题目: Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified. You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pa…
题目: Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. 代码: class Solution { public: int divide(int dividend, int divisor) { ) ? INT_MAX : INT_MIN; && dividend==INT_MIN) return INT_MAX; /…
题目: Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative. 代码: class Solution { public: string multiply(string num1, string num2) { const int n1 = n…
题目: Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). For example,S = "ADOBECODEBANC"T = "ABC" Minimum window is "BANC". Note:If there is no such wind…