二进制加法 输入2个字符串,字符串内由0和1组成:计算二者之和,返回字符串 Given two binary strings, return their sum (also a binary string). For example,a = "11"b = "1"Return "100". package com.rust.TestString; public class AddBinary { public static String addB…
/** * Source : https://oj.leetcode.com/problems/add-binary/ * * * Given two binary strings, return their sum (also a binary string). * * For example, * a = "11" * b = "1" * Return "100". */ public class AddBinary { public Str…
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) { int length = max(a.size(), b.size()); , ' '); '; while (l…
Given two binary strings, return their sum (also a binary string). For example,a = "11"b = "1"Return "100". 二进制数想加,并且保存在string中,要注意的是如何将string和int之间互相转换,并且每位相加时,会有进位的可能,会影响之后相加的结果.而且两个输入string的长度也可能会不同.这时我们需要新建一个string,它的长度是两…
(记忆线:当时一刷完是1-205. 二刷88道.下次更新记得标记不能bug-free的原因.) 88-------------Perfect Squares(完美平方数.给一个整数,求出用平方数来相加得到最小的个数) public class Solution{ public static void main(String[] args){ System.out.println(numSquares(8)); } public static int numSquares(int n){ //…
题目简述: Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". 解题思路: class Solution: # @param a, a string # @param b, a string # @return a string def addBinary(self, a, b)…
2.Add Two Numbers 原题链接https://leetcode.com/problems/add-two-numbers/ AC解: public ListNode addTwoNumbers(ListNode l1, ListNode l2) { int sum = 0; ListNode head = new ListNode(0); ListNode dummy = new ListNode(0); ListNode flag = dummy; dummy.next = he…
Count and Say 思路:递归求出n - 1时的字符串,然后双指针算出每个字符的次数,拼接在结果后面 public String countAndSay(int n) { if(n == 1) return "1"; String front = countAndSay(n - 1); int i = 0; int j = 0; String res = ""; int count = 0; while(j < front.length()){ whi…