forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: change leetcode solutions path
修改路径
- Loading branch information
Showing
2,772 changed files
with
812 additions
and
879 deletions.
There are no files selected for viewing
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
File renamed without changes.
78 changes: 39 additions & 39 deletions
78
solution/0015.3Sum/Solution.cpp → solution/0000-0099/0015.3Sum/Solution.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
class Solution { | ||
public: | ||
vector<vector<int>> threeSum(vector<int>& nums) { | ||
sort(nums.begin(),nums.end()); | ||
|
||
vector<vector<int>> ans; | ||
|
||
int sum; | ||
int len = nums.size(); | ||
int left,right; | ||
for(int i = 0; i< len;i++){ | ||
left = i + 1; | ||
right = len - 1; | ||
while(left < right){ | ||
sum = nums[i] + nums[left] + nums[right]; | ||
if(sum == 0){ | ||
vector<int> vec; | ||
vec.push_back(nums[i]); | ||
vec.push_back(nums[left]); | ||
vec.push_back(nums[right]); | ||
ans.push_back(vec); | ||
|
||
while(left < right && nums[left] == nums[left + 1])left++; | ||
while(left < right && nums[right] == nums[right - 1])right--; | ||
|
||
left++; | ||
right--; | ||
|
||
} | ||
if(sum > 0)right--; | ||
if(sum < 0)left++; | ||
} | ||
|
||
while(i<len-1 && nums[i] == nums[i+1])i++; | ||
} | ||
|
||
return ans; | ||
|
||
} | ||
class Solution { | ||
public: | ||
vector<vector<int>> threeSum(vector<int>& nums) { | ||
sort(nums.begin(),nums.end()); | ||
|
||
vector<vector<int>> ans; | ||
|
||
int sum; | ||
int len = nums.size(); | ||
int left,right; | ||
for(int i = 0; i< len;i++){ | ||
left = i + 1; | ||
right = len - 1; | ||
while(left < right){ | ||
sum = nums[i] + nums[left] + nums[right]; | ||
if(sum == 0){ | ||
vector<int> vec; | ||
vec.push_back(nums[i]); | ||
vec.push_back(nums[left]); | ||
vec.push_back(nums[right]); | ||
ans.push_back(vec); | ||
|
||
while(left < right && nums[left] == nums[left + 1])left++; | ||
while(left < right && nums[right] == nums[right - 1])right--; | ||
|
||
left++; | ||
right--; | ||
|
||
} | ||
if(sum > 0)right--; | ||
if(sum < 0)left++; | ||
} | ||
|
||
while(i<len-1 && nums[i] == nums[i+1])i++; | ||
} | ||
|
||
return ans; | ||
|
||
} | ||
}; |
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.
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.
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.
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
96 changes: 48 additions & 48 deletions
96
...n/0021.Merge Two Sorted Lists/Solution.go → ...9/0021.Merge Two Sorted Lists/Solution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
/** | ||
* Definition for singly-linked list. | ||
* type ListNode struct { | ||
* Val int | ||
* Next *ListNode | ||
* } | ||
*/ | ||
func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode { | ||
if l1==nil { | ||
return l2 | ||
} | ||
|
||
if l2==nil { | ||
return l1 | ||
} | ||
|
||
var p *ListNode | ||
|
||
if l1.Val > l2.Val { | ||
p = l2 | ||
l2 = l2.Next | ||
}else{ | ||
p = l1 | ||
l1 = l1.Next | ||
} | ||
var head *ListNode = p | ||
p.Next = nil | ||
|
||
for l1 != nil && l2 != nil { | ||
if l1.Val > l2.Val { | ||
p.Next = l2 | ||
l2 = l2.Next | ||
}else{ | ||
p.Next = l1 | ||
l1 = l1.Next | ||
} | ||
p = p.Next | ||
p.Next = nil | ||
} | ||
|
||
if l1 != nil{ | ||
p.Next = l1 | ||
} | ||
if l2 != nil{ | ||
p.Next = l2 | ||
} | ||
|
||
return head | ||
/** | ||
* Definition for singly-linked list. | ||
* type ListNode struct { | ||
* Val int | ||
* Next *ListNode | ||
* } | ||
*/ | ||
func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode { | ||
if l1==nil { | ||
return l2 | ||
} | ||
|
||
if l2==nil { | ||
return l1 | ||
} | ||
|
||
var p *ListNode | ||
|
||
if l1.Val > l2.Val { | ||
p = l2 | ||
l2 = l2.Next | ||
}else{ | ||
p = l1 | ||
l1 = l1.Next | ||
} | ||
var head *ListNode = p | ||
p.Next = nil | ||
|
||
for l1 != nil && l2 != nil { | ||
if l1.Val > l2.Val { | ||
p.Next = l2 | ||
l2 = l2.Next | ||
}else{ | ||
p.Next = l1 | ||
l1 = l1.Next | ||
} | ||
p = p.Next | ||
p.Next = nil | ||
} | ||
|
||
if l1 != nil{ | ||
p.Next = l1 | ||
} | ||
if l2 != nil{ | ||
p.Next = l2 | ||
} | ||
|
||
return head | ||
} |
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.