Skip to content

Commit 39c225b

Browse files
committed
refactor: change leetcode solutions path
修改路径
1 parent 6ad1997 commit 39c225b

File tree

2,772 files changed

+812
-879
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,772 files changed

+812
-879
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
class Solution {
2-
public:
3-
vector<vector<int>> threeSum(vector<int>& nums) {
4-
sort(nums.begin(),nums.end());
5-
6-
vector<vector<int>> ans;
7-
8-
int sum;
9-
int len = nums.size();
10-
int left,right;
11-
for(int i = 0; i< len;i++){
12-
left = i + 1;
13-
right = len - 1;
14-
while(left < right){
15-
sum = nums[i] + nums[left] + nums[right];
16-
if(sum == 0){
17-
vector<int> vec;
18-
vec.push_back(nums[i]);
19-
vec.push_back(nums[left]);
20-
vec.push_back(nums[right]);
21-
ans.push_back(vec);
22-
23-
while(left < right && nums[left] == nums[left + 1])left++;
24-
while(left < right && nums[right] == nums[right - 1])right--;
25-
26-
left++;
27-
right--;
28-
29-
}
30-
if(sum > 0)right--;
31-
if(sum < 0)left++;
32-
}
33-
34-
while(i<len-1 && nums[i] == nums[i+1])i++;
35-
}
36-
37-
return ans;
38-
39-
}
1+
class Solution {
2+
public:
3+
vector<vector<int>> threeSum(vector<int>& nums) {
4+
sort(nums.begin(),nums.end());
5+
6+
vector<vector<int>> ans;
7+
8+
int sum;
9+
int len = nums.size();
10+
int left,right;
11+
for(int i = 0; i< len;i++){
12+
left = i + 1;
13+
right = len - 1;
14+
while(left < right){
15+
sum = nums[i] + nums[left] + nums[right];
16+
if(sum == 0){
17+
vector<int> vec;
18+
vec.push_back(nums[i]);
19+
vec.push_back(nums[left]);
20+
vec.push_back(nums[right]);
21+
ans.push_back(vec);
22+
23+
while(left < right && nums[left] == nums[left + 1])left++;
24+
while(left < right && nums[right] == nums[right - 1])right--;
25+
26+
left++;
27+
right--;
28+
29+
}
30+
if(sum > 0)right--;
31+
if(sum < 0)left++;
32+
}
33+
34+
while(i<len-1 && nums[i] == nums[i+1])i++;
35+
}
36+
37+
return ans;
38+
39+
}
4040
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
1-
/**
2-
* Definition for singly-linked list.
3-
* type ListNode struct {
4-
* Val int
5-
* Next *ListNode
6-
* }
7-
*/
8-
func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode {
9-
if l1==nil {
10-
return l2
11-
}
12-
13-
if l2==nil {
14-
return l1
15-
}
16-
17-
var p *ListNode
18-
19-
if l1.Val > l2.Val {
20-
p = l2
21-
l2 = l2.Next
22-
}else{
23-
p = l1
24-
l1 = l1.Next
25-
}
26-
var head *ListNode = p
27-
p.Next = nil
28-
29-
for l1 != nil && l2 != nil {
30-
if l1.Val > l2.Val {
31-
p.Next = l2
32-
l2 = l2.Next
33-
}else{
34-
p.Next = l1
35-
l1 = l1.Next
36-
}
37-
p = p.Next
38-
p.Next = nil
39-
}
40-
41-
if l1 != nil{
42-
p.Next = l1
43-
}
44-
if l2 != nil{
45-
p.Next = l2
46-
}
47-
48-
return head
1+
/**
2+
* Definition for singly-linked list.
3+
* type ListNode struct {
4+
* Val int
5+
* Next *ListNode
6+
* }
7+
*/
8+
func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode {
9+
if l1==nil {
10+
return l2
11+
}
12+
13+
if l2==nil {
14+
return l1
15+
}
16+
17+
var p *ListNode
18+
19+
if l1.Val > l2.Val {
20+
p = l2
21+
l2 = l2.Next
22+
}else{
23+
p = l1
24+
l1 = l1.Next
25+
}
26+
var head *ListNode = p
27+
p.Next = nil
28+
29+
for l1 != nil && l2 != nil {
30+
if l1.Val > l2.Val {
31+
p.Next = l2
32+
l2 = l2.Next
33+
}else{
34+
p.Next = l1
35+
l1 = l1.Next
36+
}
37+
p = p.Next
38+
p.Next = nil
39+
}
40+
41+
if l1 != nil{
42+
p.Next = l1
43+
}
44+
if l2 != nil{
45+
p.Next = l2
46+
}
47+
48+
return head
4949
}

0 commit comments

Comments
 (0)