Description Given two binary strings, return their sum (also a binary string). For example, a = “11” b = “1” Return “100”. Solution class Solution {public:string addBinary(string a, string b)
前面在获取功能,我们有很多方法没有介绍,这些方法都是和Map遍历相关结合使用的方法。这篇,我们来看看Map如何进行遍历和如何进行键找值。 通过阅读API,我们看到Map接口并没有Iterator这样的迭代器方法,那么HashMap对象是如何来遍历元素的呢。下面,我们分别用Set集合的迭代器方法和增强for循环去实现HashMap集合遍历。在之前,我们需要阅读Map API
题目: Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:Try to come up as many solutions as you can,
题目: 题解: void reserve(char* s) {int len = strlen(s);for (int i = 0; i < len / 2; i++) {char t = s[i];s[i] = s[len - i - 1], s[len - i - 1] = t;}}char* addBinary(char* a, char* b) {reserve(a);reser
题目: 题解: class Solution {public String addBinary(String a, String b) {StringBuffer ans = new StringBuffer();int n = Math.max(a.length(), b.length()), carry = 0;for (int i = 0; i < n; ++i) {carry +=
题目: 题解: class Solution {public:string addBinary(string a, string b) {string ans;reverse(a.begin(), a.end());reverse(b.begin(), b.end());int n = max(a.size(), b.size()), carry = 0;for (size_t i =
题目描述 题目难度:Easy 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” Outp
题目:Maximum path sum I Maximum path sum II By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23. 3 7 4 2 4 6 8 5