随笔分类 -  牛客网华为机试训练

摘要:一:解题思路 这道题目和leetcode72题,编辑距离差不多,只是定义2个字符串距离不一样而已。可以放在一起进行学习。Time:O(m*n),Space:O(m*n) 二:完整代码示例 (C++版和Java版) C++代码: #include<iostream> #include<vector> 阅读全文
posted @ 2020-07-31 12:20 repinkply 阅读(479) 评论(0) 推荐(0)
摘要:这道题目和leetcode88 合并2个有序数组有点类似,可以放在一起练习。 C++代码如下: #include<iostream> #include<vector> #include <set> #include <algorithm> using namespace std; int main( 阅读全文
posted @ 2020-07-30 22:06 repinkply 阅读(168) 评论(0) 推荐(0)
摘要:这道题目是不是从长字符串中匹配子串的问题,而是一个更简单的问题。 C++代码如下: #include<iostream> #include<string> using namespace std; int main() { string sShort = ""; string sLong = ""; 阅读全文
posted @ 2020-07-30 21:34 repinkply 阅读(611) 评论(0) 推荐(0)
摘要:C++代码: #include<iostream> #include<string> using namespace std; int main() { char ch='0'; int a = 0; int b =0; while (cin >> a >> ch >> b) { while (a 阅读全文
posted @ 2020-07-30 20:50 repinkply 阅读(583) 评论(0) 推荐(0)
摘要:这道题目和leetcode5 最长回文子串 是一样的。这里需要强调一点就是,C++中 string类中,substr(a,b) a是要截取字符串的起始坐标,b是指要截取字符串的长度。Java String类中 substring(a,b)中 a的含义一样,但是b是要截取字符串的尾坐标,这个和C++ 阅读全文
posted @ 2020-07-30 18:32 repinkply 阅读(293) 评论(0) 推荐(0)
摘要:C++代码如下: #include <iostream> #include <algorithm> using namespace std; int main() { int n = 0; while (cin >> n) { int count = 0; int maxCount = 0; whi 阅读全文
posted @ 2020-07-30 17:23 repinkply 阅读(229) 评论(0) 推荐(0)
摘要:C++代码如下: #include <iostream> #include <string> using namespace std; int main() { string s=""; while (getline(cin, s)) { int val = 0; int len = s.size( 阅读全文
posted @ 2020-07-30 15:43 repinkply 阅读(620) 评论(0) 推荐(0)
摘要:C++代码如下: #include <iostream> #include <vector> using namespace std; int main() { vector<int> nums(4,0); vector<char> ch(3); while (cin >> nums[0] >> c 阅读全文
posted @ 2020-07-29 21:41 repinkply 阅读(302) 评论(0) 推荐(0)
摘要:这道题目和 leetcode62 路径数量一样的,唯一不同的就是牛客网n,m需要加1,这样才能够运行。 #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; 阅读全文
posted @ 2020-07-29 21:24 repinkply 阅读(165) 评论(0) 推荐(0)
摘要:C++代码: #include <iostream> #include <string> #include <vector> using namespace std; int main() { string str = ""; while (cin >> str) { vector<string> 阅读全文
posted @ 2020-07-29 20:49 repinkply 阅读(362) 评论(0) 推荐(0)
摘要:C++代码如下: #include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <numeric> using namespace std; bool DFS(vector<int> &num 阅读全文
posted @ 2020-07-29 17:36 repinkply 阅读(200) 评论(0) 推荐(0)
摘要:输入输出格式一定要与样例一样,连一个空格,逗号都不能少,否者就会报错。 C++代码如下: #include <iostream> #include <vector> #include <string> #include <map> using namespace std; int main() { 阅读全文
posted @ 2020-07-29 16:32 repinkply 阅读(569) 评论(0) 推荐(0)
摘要:C++代码如下: #include <iostream> #include <iomanip> using namespace std; int main() { int n = 0; while (cin >> n) { int count = 0; int negativeCount=0; do 阅读全文
posted @ 2020-07-29 12:02 repinkply 阅读(461) 评论(0) 推荐(0)
摘要:C++代码如下: #include <iostream> #include <string> #include <cctype> using namespace std; int main() { string str = ""; while (cin >> str) { if (isdigit(s 阅读全文
posted @ 2020-07-28 21:55 repinkply 阅读(361) 评论(0) 推荐(0)
摘要:一:解题思路 Time:O(n*log(n)) Space:O(n) 二:完整代码示例 (C++版和Java版) #include <iostream> #include <vector> #include <string> #include <map> #include <algorithm> u 阅读全文
posted @ 2020-07-28 16:36 repinkply 阅读(285) 评论(0) 推荐(0)
摘要:一:解题思路 这道题目和 leetcode69 题,求解x的平方根有些类似。都是采用二分的思想来做,可以对比分析。 二:完整代码示例 (C++版和Java版) C++: #include <iostream> using namespace std; double getCubeRoot(doubl 阅读全文
posted @ 2020-07-26 20:53 repinkply 阅读(370) 评论(0) 推荐(0)