码迷,mamicode.com
首页 >  
搜索关键字:解答    ( 4882个结果
【字符串】面试题67. 把字符串转换成整数(atoi)
题目: 解答: 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
【字符串】537. 复数乘法
题目: 解答: 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
【字符串】539. 最小时间差
题目: 解答: 思路: 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
【字符串】583. 两个字符串的删除操作
题目: 解答: 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
【字符串】556. 下一个更大元素 III
题目: 解答: 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
Leetcode 055. 跳跃游戏 贪心
地址 https://leetcode-cn.com/problems/jump-game/ 给定一个非负整数数组,你最初位于数组的第一个位置。 数组中的每个元素代表你在该位置可以跳跃的最大长度。 判断你是否能够到达最后一个位置。 示例 1: 输入: [2,3,1,1,4] 输出: true 解释: ...
分类:其他好文   时间:2020-05-04 13:36:25    阅读次数:53
【字符串】165. 比较版本号
题目: 解答: 方法一:分割+解析,两次遍历,线性空间。 第一个想法是将两个字符串按点字符分割成块,然后逐个比较这些块。 如果两个版本号的块数相同,则可以有效工作。如果不同,则需要在较短字符串末尾补充相应的 .0 块数使得块数相同。 算法: (1)根据点分割两个字符串将分割的结果存储到数组中。(2) ...
分类:其他好文   时间:2020-05-04 13:36:04    阅读次数:52
【字符串】49. 字母异位词分组
题目: 解答: 因为要找组成一样的单词,如何判断?最简单的,一排序,如果是同一个单词,那么就是组成一样的。比如 “eat” "tea" 排序后都为 “aet”。只要引入一个hash表,索引是排序后的单词,值为结果vector的下标,循环一遍就好了。 1 class Solution { 2 publ ...
分类:其他好文   时间:2020-05-04 13:33:06    阅读次数:46
【字符串】678. 有效的括号字符串
题目: 解答: 这道题因为只需要判断是否可以构成有效的括号,并不需要列举出合法的解。可以直接遍历一遍字符串,记录出现的括号和*的情况。 1 class Solution { 2 public: 3 bool checkValidString(string s) 4 { 5 // left和star分 ...
分类:其他好文   时间:2020-05-04 13:27:25    阅读次数:44
【字符串】151. 翻转字符串里的单词
题目: 解答: 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
4882条   上一页 1 ... 28 29 30 31 32 ... 489 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!