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&qu…
Given two binary strings, return their sum (also a binary string). For example,a = "11"b = "1"Return "100". 解题思路: 从两个子字符尾部遍历字符: 每次得到新的字符插入结果字符串的头部: 解题步骤: 1.建立返回string.从后向前遍历的idx:idx_a / idx_b.进位量2.循环开始,当idx_a或者idx_b任意不为0时,循环继…
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. Solution 1 : 十进制加法 class Solution { public: vector<int> plusO…
, INVALID}; int g_status; long long SubStrToInt(const char* str, bool minus) { ; : ; while (*str != '\0') { ') { num = num * + flag * (*str - '); if ((!minus && num > 0x7FFFFFFF) || (minus && num < (signed int)0x80000000)) { num = ;…
Given two binary strings, return their sum (also a binary string). For example,a = "11"b = "1"Return "100". 题解:简单的二进制加法模拟.a,b的最后以为对齐开始进行加法,用carries保存进位,如果加完后最高位还有进位,那么要在结果的最前面加一个1. 代码如下: public class Solution { public String…
解法一:Brute-force int strStr(string haystack, string needle) { int m = haystack.size(); int n = needle.size(); if (!n) ; ; i < m - n + ; ++i) { ; while (j < n) { if (needle[j] == haystack[k]) { j++; k++; } else { break; } } if (j == n) return i; } ; }…