两个寄存器
Google [LC43. 大数乘法] string multiply(string num1, string num2) { string res; int n1 = num1.size(), n2 = num2.size(); int k = n1 + n2 - 2, carry = 0; vector<int> v(n1 + n2, 0); for (int i = 0; i < n1; ++i) { for (int j = 0; j < n2; ++j) { v[k - i - j] += (num1[i] - '0') * (num2[j] - '0'); } } for (int i = 0; i < n1 + n2; ++i) { v[i] += carry; carry = v[i] / 10; v[i] %= 10; } int i = n1 + n2 - 1; while (v[i] == 0) --i; if (i < 0) return "0"; while (i >= 0) res.push_back(v[i--] + '0'); return res; }
[Course Schedule] (https://leetcode.com/problems/course-schedule/description/) There are a total of n courses you have to take, labeled from 0 to n - 1 e.g. 2, [[1,0]] There are a total of 2 courses to take. To take course 1 you should have finished course 0. So it is possible.
LC3: [Longest substring without repeated chars] (https://leetcode.com/problems/longest-substring-without-repeating-characters/description/)
原题链接:[LC815] (https://leetcode.com/problems/bus-routes/description/)
Installation
本系列文章在 https://github.com/mzlogin/rtfsc-android 持续更新中,欢迎有兴趣的童鞋们关注。