随笔分类 - 牛客网华为机试训练
摘要:一:解题思路 这道题目和leetcode72题,编辑距离差不多,只是定义2个字符串距离不一样而已。可以放在一起进行学习。Time:O(m*n),Space:O(m*n) 二:完整代码示例 (C++版和Java版) C++代码: #include<iostream> #include<vector>
阅读全文
摘要:这道题目和leetcode88 合并2个有序数组有点类似,可以放在一起练习。 C++代码如下: #include<iostream> #include<vector> #include <set> #include <algorithm> using namespace std; int main(
阅读全文
摘要:这道题目是不是从长字符串中匹配子串的问题,而是一个更简单的问题。 C++代码如下: #include<iostream> #include<string> using namespace std; int main() { string sShort = ""; string sLong = "";
阅读全文
摘要: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
阅读全文
摘要:这道题目和leetcode5 最长回文子串 是一样的。这里需要强调一点就是,C++中 string类中,substr(a,b) a是要截取字符串的起始坐标,b是指要截取字符串的长度。Java String类中 substring(a,b)中 a的含义一样,但是b是要截取字符串的尾坐标,这个和C++
阅读全文
摘要:C++代码如下: #include <iostream> #include <algorithm> using namespace std; int main() { int n = 0; while (cin >> n) { int count = 0; int maxCount = 0; whi
阅读全文
摘要:C++代码如下: #include <iostream> #include <string> using namespace std; int main() { string s=""; while (getline(cin, s)) { int val = 0; int len = s.size(
阅读全文
摘要:C++代码如下: #include <iostream> #include <vector> using namespace std; int main() { vector<int> nums(4,0); vector<char> ch(3); while (cin >> nums[0] >> c
阅读全文
摘要:这道题目和 leetcode62 路径数量一样的,唯一不同的就是牛客网n,m需要加1,这样才能够运行。 #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std;
阅读全文
摘要:C++代码: #include <iostream> #include <string> #include <vector> using namespace std; int main() { string str = ""; while (cin >> str) { vector<string>
阅读全文
摘要:C++代码如下: #include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <numeric> using namespace std; bool DFS(vector<int> &num
阅读全文
摘要:输入输出格式一定要与样例一样,连一个空格,逗号都不能少,否者就会报错。 C++代码如下: #include <iostream> #include <vector> #include <string> #include <map> using namespace std; int main() {
阅读全文
摘要:C++代码如下: #include <iostream> #include <iomanip> using namespace std; int main() { int n = 0; while (cin >> n) { int count = 0; int negativeCount=0; do
阅读全文
摘要:C++代码如下: #include <iostream> #include <string> #include <cctype> using namespace std; int main() { string str = ""; while (cin >> str) { if (isdigit(s
阅读全文
摘要:一:解题思路 Time:O(n*log(n)) Space:O(n) 二:完整代码示例 (C++版和Java版) #include <iostream> #include <vector> #include <string> #include <map> #include <algorithm> u
阅读全文
摘要:一:解题思路 这道题目和 leetcode69 题,求解x的平方根有些类似。都是采用二分的思想来做,可以对比分析。 二:完整代码示例 (C++版和Java版) C++: #include <iostream> using namespace std; double getCubeRoot(doubl
阅读全文

浙公网安备 33010602011771号