Skip to content

Commit 8d0aa16

Browse files
author
xiapengchng
committed
Update Solution 014 with cpp version
1 parent 1ecbebe commit 8d0aa16

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
static int x=[](){
2+
std::ios::sync_with_stdio(false);
3+
cin.tie(NULL);
4+
return 0;
5+
}();
6+
string Compare(string s1,string s2)
7+
{
8+
if(s1.size()==0||s2.size()==0)
9+
return "";
10+
int num=s1.size()<s2.size()?s1.size():s2.size();
11+
string s;
12+
for(int i=0;i<num;i++)
13+
{
14+
if(s1[i]==s2[i])
15+
{
16+
s.push_back(s1[i]);
17+
}
18+
else
19+
break;
20+
21+
}
22+
return s;
23+
}
24+
class Solution {
25+
public:
26+
string longestCommonPrefix(vector<string>& strs) {
27+
if(strs.size()==0)
28+
return "";
29+
string prefix=strs[0];
30+
for(int i=1;i<strs.size();i++)
31+
{
32+
prefix=Compare(prefix,strs[i]);
33+
}
34+
return prefix;
35+
36+
}
37+
};
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
int uniquePaths(int m, int n) {
4+
if(m<=0||n<=0)
5+
return 0;
6+
if(m==1||n==1)
7+
return 1;
8+
int arr[m][n]={0};
9+
arr[0][0]=1;
10+
for(int i=1;i<m;i++)
11+
arr[i][0]=1;
12+
for(int j=1;j<n;j++)
13+
arr[0][j]=1;
14+
for(int i=1;i<m;i++)
15+
for(int j=1;j<n;j++)
16+
{
17+
arr[i][j]=arr[i-1][j]+arr[i][j-1];
18+
}
19+
return arr[m-1][n-1];
20+
}
21+
};

0 commit comments

Comments
 (0)