Skip to content

Commit 7cb1fe2

Browse files
authored
Merge branch 'master' into master
2 parents 80f6bef + d5129cb commit 7cb1fe2

File tree

14 files changed

+230
-29
lines changed

14 files changed

+230
-29
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,6 @@ I'm looking for long-term contributors/partners to this repo! Send me [PRs](http
130130
| <center> [<img src="https://avatars3.githubusercontent.com/u/21008209?v=4" width="80px;"/>](https://github.com/yanglbme) </center> | <center> [<img src="https://avatars3.githubusercontent.com/u/23625436?v=4" width="80px;"/>](https://github.com/chakyam) </center> | <center> [<img src="https://avatars3.githubusercontent.com/u/10081554?v=4" width="80px;"/>](https://github.com/zhkmxx9302013) </center> | <center> [<img src="https://avatars3.githubusercontent.com/u/40383345?v=4" width="80px;"/>](https://github.com/MarkKuang1991) </center> | <center> [<img src="https://avatars3.githubusercontent.com/u/12371194?v=4" width="80px;"/>](https://github.com/fonxian) </center> | <center> [<img src="https://avatars3.githubusercontent.com/u/25222367?v=4" width="80px;"/>](https://github.com/zhanary) </center> | <center> [<img src="https://avatars3.githubusercontent.com/u/42396616?v=4" width="80px;"/>](https://github.com/ZhouTingZhaobiu) </center> | <center> [<img src="https://avatars3.githubusercontent.com/u/31923541?v=4" width="80px;"/>](https://github.com/zouwx2cs) </center> |
131131
|---|---|---|---|---|---|---|---|
132132
| <center> [<img src="https://avatars3.githubusercontent.com/u/20679510?v=4" width="80px;"/>](https://github.com/Mrzhudky) </center> | <center> [<img src="https://avatars3.githubusercontent.com/u/44309823?v=4" width="80px;"/>](https://github.com/KongJHong) </center> | <center> [<img src="https://avatars3.githubusercontent.com/u/18181519?v=4" width="80px;"/>](https://github.com/limbowandering) </center> | <center> [<img src="https://avatars3.githubusercontent.com/u/37685012?v=4" width="80px;"/>](https://github.com/jxdeng3989) </center> | <center> [<img src="https://avatars3.githubusercontent.com/u/44314231?v=4" width="80px;"/>](https://github.com/igayhub) </center> | <center> [<img src="https://avatars3.githubusercontent.com/u/30177307?v=4" width="80px;"/>](https://github.com/MCN1998) </center> | <center> [<img src="https://avatars3.githubusercontent.com/u/5793058?v=4" width="80px;"/>](https://github.com/Fairyhead) </center> | <center> [<img src="https://avatars3.githubusercontent.com/u/24841082?v=4" width="80px;"/>](https://github.com/zhng1456) </center> |
133-
| <center> [<img src="https://avatars3.githubusercontent.com/u/32598987?v=4" width="80px;"/>](https://github.com/xiapengchng) </center> | <center> [<img src="https://avatars3.githubusercontent.com/u/37660444?v=4" width="80px;"/>](https://github.com/Mcnwork2018) </center> | <center> [<img src="https://avatars3.githubusercontent.com/u/22535595?v=4" width="80px;"/>](https://github.com/bluesword12350) </center> |
133+
| <center> [<img src="https://avatars3.githubusercontent.com/u/32598987?v=4" width="80px;"/>](https://github.com/xiapengchng) </center> | <center> [<img src="https://avatars3.githubusercontent.com/u/37660444?v=4" width="80px;"/>](https://github.com/Mcnwork2018) </center> | <center> [<img src="https://avatars3.githubusercontent.com/u/22535595?v=4" width="80px;"/>](https://github.com/bluesword12350) </center> | <center> [<img src="https://avatars3.githubusercontent.com/u/39827514?v=4" width="80px;"/>](https://github.com/ashwek) </center> |
134134

135135
<!-- ALL-CONTRIBUTORS-LIST:END -->
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def isPalindrome(self, num):
3+
"""
4+
:type num: int
5+
:rtype: bool
6+
"""
7+
if num < 0:
8+
return False
9+
10+
return str(num) == str(num)[::-1]
Lines changed: 37 additions & 0 deletions
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+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int threeSumClosest(int[] nums, int target) {
3+
int result = nums[0]+nums[1]+nums[2];
4+
Arrays.sort(nums);
5+
for(int i = 0;i<nums.length-2;i++){
6+
int start = i+1,end=nums.length-1;
7+
while(start<end){
8+
int cache = nums[i]+nums[start]+nums[end];
9+
if(Math.abs(cache-target)<Math.abs(result-target)) result = cache;
10+
if(cache < target ) start++;
11+
else if(cache > target) end--;
12+
else return result;
13+
}
14+
}
15+
return result;
16+
}
17+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class Solution {
2+
public List<String> letterCombinations(String digits) {
3+
char[] cs = digits.toCharArray();
4+
List<String> result = new ArrayList<>();
5+
for (char a : cs) {
6+
char[] charArray;
7+
switch (a) {
8+
case '2': charArray = new char[]{'a','b','c'}; break;
9+
case '3': charArray = new char[]{'d','e','f'}; break;
10+
case '4': charArray = new char[]{'g','h','i'}; break;
11+
case '5': charArray = new char[]{'j','k','l'}; break;
12+
case '6': charArray = new char[]{'m','n','o'}; break;
13+
case '7': charArray = new char[]{'p','q','r','s'}; break;
14+
case '8': charArray = new char[]{'t','u','v'}; break;
15+
case '9': charArray = new char[]{'w','x','y','z'}; break;
16+
default: return null;
17+
}
18+
if (result.size() == 0) {
19+
for (char aCharArray : charArray) result.add(String.valueOf(aCharArray));
20+
} else {
21+
List<String> cache = new ArrayList<>();
22+
for (String string : result) {
23+
for (char aCharArray : charArray) cache.add(string + aCharArray);
24+
}
25+
result = cache;
26+
}
27+
}
28+
return result;
29+
}
30+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* struct ListNode {
4+
* int val;
5+
* ListNode *next;
6+
* ListNode(int x) : val(x), next(NULL) {}
7+
* };
8+
*/
9+
class Solution {
10+
public:
11+
ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
12+
ListNode *a1=new ListNode(0);
13+
ListNode *head=a1;
14+
while(l1!=NULL&&l2!=NULL)
15+
{
16+
if(l1->val<l2->val)
17+
{
18+
a1->next=l1;
19+
l1=l1->next;
20+
a1=a1->next;
21+
}
22+
else
23+
{
24+
a1->next=l2;
25+
l2=l2->next;
26+
a1=a1->next;
27+
}
28+
}
29+
if(l1==NULL)
30+
a1->next=l2;
31+
if(l2==NULL)
32+
a1->next=l1;
33+
return head->next;
34+
35+
36+
}
37+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const maxSubArray = function(nums){
2+
if(nums.length === 0) return 0;
3+
let ans = nums[0], tmp = nums[0];
4+
for(let i = 1; i < nums.length; i++){
5+
tmp = Math.max(tmp+nums[i], nums[i]);
6+
ans = Math.max(ans,tmp);
7+
}
8+
return ans;
9+
}
Lines changed: 21 additions & 0 deletions
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+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
int climbStairs(int n) {
4+
5+
if(n==1)
6+
return 1;
7+
if(n==2)
8+
return 2;
9+
int arr[n]={0};
10+
arr[0]=1;
11+
arr[1]=2;
12+
for(int i=2;i<n;i++)
13+
arr[i]=arr[i-1]+arr[i-2];
14+
return arr[n-1];
15+
16+
}
17+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const climbStairs = function(n){
2+
let arr = [];
3+
arr[0] = 1;
4+
arr[1] = 1;
5+
for(let i = 2; i <= n; i++){
6+
arr[i] = arr[i-1]+arr[i-2];
7+
}
8+
return arr[n];
9+
};

0 commit comments

Comments
 (0)