AddBinary】的更多相关文章

二进制加法 输入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,它的长度是两…
Array 448.找出数组中所有消失的数 要求:整型数组取值为 1 ≤ a[i] ≤ n,n是数组大小,一些元素重复出现,找出[1,n]中没出现的数,实现时时间复杂度为O(n),并不占额外空间 思路1:(discuss)用数组下标标记未出现的数,如出现4就把a[3]的数变成负数,当查找时判断a的正负就能获取下标 tips:注意数组溢出 public List<Integer> findDisappearedNumbers(int[] nums) { List<Integer> d…
利用堆栈:http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/http://oj.leetcode.com/problems/longest-valid-parentheses/ (也可以用一维数组,贪心)http://oj.leetcode.com/problems/valid-parentheses/http://oj.leetcode.com/problems/largest-rectangle-in-histo…
(记忆线:当时一刷完是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…