forked from wisdompeak/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 1
[pull] master from wisdompeak:master #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
19ce837
Create 2322.Minimum-Score-After-Removals-on-a-Tree.cpp
wisdompeak d145aa5
Update Readme.md
wisdompeak 092df5a
Update 2311.Longest-Binary-Subsequence-Less-Than-or-Equal-to-K_v1.cpp
wisdompeak 07fb2b5
Update Readme.md
wisdompeak e74d781
Update 327.Count-of-Range-Sum.cpp
wisdompeak de74fd8
Update 327.Count-of-Range-Sum.cpp
wisdompeak 9f284b5
Update Readme.md
wisdompeak 9e8fe66
Update Readme.md
wisdompeak 96355ed
Update Readme.md
wisdompeak fe1779d
Update 315.Count-of-Smaller-Numbers-After-Self.cpp
wisdompeak a5504ee
Update 1649.Create-Sorted-Array-through-Instructions_DivideConque.cpp
wisdompeak c30a5cc
Update 2141.Maximum-Running-Time-of-N-Computers.cpp
wisdompeak 814052e
Create Readme.md
wisdompeak df6a1de
Create 2321.Maximum-Score-Of-Spliced-Array.cpp
wisdompeak ebee723
Update Readme.md
wisdompeak 289068f
Update 2322.Minimum-Score-After-Removals-on-a-Tree.cpp
wisdompeak 72d51bc
Create Readme.md
wisdompeak fdf2f4c
Create 2320.Count-Number-of-Ways-to-Place-Houses.cpp
wisdompeak 8069772
Update Readme.md
wisdompeak 8f62433
Create 2320.Count-Number-of-Ways-to-Place-Houses_v2.cpp
wisdompeak 89cbb34
Update and rename 2320.Count-Number-of-Ways-to-Place-Houses.cpp to 23...
wisdompeak 1e355d5
Create 2320.Count-Number-of-Ways-to-Place-Houses_v3.cpp
wisdompeak 7919316
Create Readme.md
wisdompeak 0c1c944
Create 2318.Number-of-Distinct-Roll-Sequences.cpp
wisdompeak b50deba
Update Readme.md
wisdompeak 06aa0b0
Create Readme.md
wisdompeak d586a6b
Update 2318.Number-of-Distinct-Roll-Sequences.cpp
wisdompeak b72aba5
Update 1268.Search-Suggestions-System_v1.cpp
wisdompeak 7d9a6fe
Update Readme.md
wisdompeak 397844f
Create 1102.Path-With-Maximum-Minimum-Value.cpp_v2.cpp
wisdompeak d038b71
Update Readme.md
wisdompeak 7a5ee83
Update 1102.Path-With-Maximum-Minimum-Value.cpp_v2.cpp
wisdompeak d05b324
Update 1102.Path-With-Maximum-Minimum-Value.cpp
wisdompeak 8012977
Rename 1102.Path-With-Maximum-Minimum-Value.cpp to 1102.Path-With-Max...
wisdompeak cdaf272
Rename 1102.Path-With-Maximum-Minimum-Value.cpp_v2.cpp to 1102.Path-W...
wisdompeak c1173a7
Update Readme.md
wisdompeak e0ae1fb
Update Readme.md
wisdompeak 407df52
Update Readme.md
wisdompeak aee6d6d
Update Readme.md
wisdompeak afa8f7c
Update Readme.md
wisdompeak adbf372
Update Readme.md
wisdompeak cdce66c
Update Readme.md
wisdompeak a1c4767
Update 1388.Pizza-With-3n-Slices.cpp
wisdompeak 56d6d6b
Update Readme.md
wisdompeak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Create 2321.Maximum-Score-Of-Spliced-Array.cpp
- Loading branch information
commit df6a1dea2d99e3e82220f70bfb91612d0c7f457a
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
...c_Programming/2321.Maximum-Score-Of-Spliced-Array/2321.Maximum-Score-Of-Spliced-Array.cpp
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class Solution { | ||
public: | ||
int maximumsSplicedArray(vector<int>& nums1, vector<int>& nums2) | ||
{ | ||
return max(solve(nums1,nums2), solve(nums2,nums1)); | ||
} | ||
int solve(vector<int>& nums1, vector<int>& nums2) | ||
{ | ||
int n = nums1.size(); | ||
vector<int>nums(n); | ||
for (int i=0; i<n; i++) | ||
{ | ||
nums[i] = nums1[i]-nums2[i]; | ||
} | ||
|
||
int curSum = 0; | ||
int ret = 0; | ||
for (int i=0; i<n; i++) | ||
{ | ||
curSum = max(curSum + nums[i], nums[i]); | ||
ret = max(ret, curSum); | ||
} | ||
|
||
int sum = accumulate(nums2.begin(), nums2.end(), 0); | ||
|
||
return sum + ret; | ||
} | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.