Java for LeetCode 067 Add Binary】的更多相关文章

Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". 解题思路: JAVA实现如下: static public String addBinary(String a, String b) { if (a.length() < b.length()) { String temp…
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example, Given n = 3, your program should return all 5 unique BST's shown below. 解题思路: 参考Java for LeetCode 096 Unique Binary Search Trees思路,本题很容易解决.注意,…
1 题目 Given two binary strings, return their sum (also a binary string). For example,a = "11"b = "1"Return "100". 接口 String addBinary(String a, String b) 2 思路 处理二进制求和和进位.从低位开始,一直相加并且维护进位.和Add Two Numbers的区别是这个题目低位在后面,所以要从strin…
Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes with keys…
Design a data structure that supports the following two operations: void addWord(word)bool search(word) search(word) can search a literal word or a regular expression string containing only letters a-z or .. A . means it can represent any one letter.…
题目描述: Given two binary strings, return their sum (also a binary string). For example,a = "11"b = "1"Return "100". 解题思路: 使用StringBuilder,且使用进位. 代码如下: public class Solution { public String addBinary(String a, String b) { String…
Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 解题思路一: preorder[0]为root,以此分别划分出inorderLeft.preorderLeft.inorderRight.preorderRight四个数组,然后root.left=buildTree(pre…
Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. 解题思路: 先中序遍历找到mistake,然后替换即可,JAVA实现如下: public void recoverTree(TreeNode root) { List<Integer> list = inorderTraversal(root); int left…
Given two binary strings, return their sum (also a binary string). For example,a = "11"b = "1"Return "100". 题目标签:Math 题目给了我们两个string a 和 b,让我们把这两个二进制 相加. 首先把两个string 的长度得到,然后从右向左 取 两个string 的 digit. 增设一个 carry = 0: 每一轮把 digit…
Given two binary strings, return their sum (also a binary string). The input strings are both non-empty and contains only characters 1 or 0. Example 1: Input: a = "11", b = "1" Output: "100" Example 2: Input: a = "1010&q…