题目: 解答: 1 class Solution { 2 public: 3 int strToInt(string str) 4 { 5 if (str.size() == 0) 6 { 7 return 0; 8 } 9 10 int i = 0; 11 int minus = 1; 12 13 ...
分类:
其他好文 时间:
2020-05-04 15:39:35
阅读次数:
54
题目: 解答: 1 class Solution { 2 public: 3 string complexNumberMultiply(string a, string b) 4 { 5 int a1 = stoi(a); 6 int b1 = stoi(b); 7 8 int i = 0; 9 i ...
分类:
其他好文 时间:
2020-05-04 13:49:29
阅读次数:
58
题目: 解答: 思路: 1,时间转化为分钟数; 2,然后对数字进行排序,进行比较; 3,注意头部和尾部时间的比较时需要考虑不同的方向; 1 class Solution { 2 public: 3 const int DAY_MINUTE = 24 * 60; 4 int time2int(cons ...
分类:
其他好文 时间:
2020-05-04 13:43:32
阅读次数:
61
题目: 解答: 1 class Solution { 2 public: 3 int minDistance(string word1, string word2) 4 { 5 int N1 = word1.size(); 6 int N2 = word2.size(); 7 8 vector<ve ...
分类:
其他好文 时间:
2020-05-04 13:42:38
阅读次数:
53
题目: 解答: 1 class Solution { 2 public: 3 vector<int> digits(int n) 4 { 5 vector<int> res; 6 while (n > 0) 7 { 8 res.push_back(n % 10); 9 n /= 10; 10 } 1 ...
分类:
其他好文 时间:
2020-05-04 13:39:01
阅读次数:
64
地址 https://leetcode-cn.com/problems/jump-game/ 给定一个非负整数数组,你最初位于数组的第一个位置。 数组中的每个元素代表你在该位置可以跳跃的最大长度。 判断你是否能够到达最后一个位置。 示例 1: 输入: [2,3,1,1,4] 输出: true 解释: ...
分类:
其他好文 时间:
2020-05-04 13:36:25
阅读次数:
53
题目: 解答: 方法一:分割+解析,两次遍历,线性空间。 第一个想法是将两个字符串按点字符分割成块,然后逐个比较这些块。 如果两个版本号的块数相同,则可以有效工作。如果不同,则需要在较短字符串末尾补充相应的 .0 块数使得块数相同。 算法: (1)根据点分割两个字符串将分割的结果存储到数组中。(2) ...
分类:
其他好文 时间:
2020-05-04 13:36:04
阅读次数:
52
题目: 解答: 因为要找组成一样的单词,如何判断?最简单的,一排序,如果是同一个单词,那么就是组成一样的。比如 “eat” "tea" 排序后都为 “aet”。只要引入一个hash表,索引是排序后的单词,值为结果vector的下标,循环一遍就好了。 1 class Solution { 2 publ ...
分类:
其他好文 时间:
2020-05-04 13:33:06
阅读次数:
46
题目: 解答: 这道题因为只需要判断是否可以构成有效的括号,并不需要列举出合法的解。可以直接遍历一遍字符串,记录出现的括号和*的情况。 1 class Solution { 2 public: 3 bool checkValidString(string s) 4 { 5 // left和star分 ...
分类:
其他好文 时间:
2020-05-04 13:27:25
阅读次数:
44
题目: 解答: 1 class Solution { 2 public: 3 string reverseWords(string s) 4 { 5 if (s.empty()) 6 { 7 return s; 8 } 9 10 int len = 0; 11 string ans = ""; 12 ...
分类:
其他好文 时间:
2020-05-04 13:24:26
阅读次数:
53