Skip to content
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

New Solutions #38

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Beginner level/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,26 @@ This folder contains solutions to problems that are suitable for beginners in pr
# Beginner-Level-Solutions.:bulb:
| # | Title | Difficulty | Topic | Video | Python | C++ | C |
| ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ----------------------- | --------------------------------------------------------- | ----------------------------------------------------------------- | --- | --- |
|58|[Length of Last Word](https://leetcode.com/problems/length-of-last-word/)|Easy|Array&Hashing||[Solution](../Solutions/python3/58.py)||[Solution](../Solutions/C/58-Length-of-Last-Word.c)|
|217|[ Contains Duplicate](https://leetcode.com/problems/contains-duplicate/)|Easy|Array&Hashing|[Video](https://www.youtube.com/watch?v=zfRMonn79wQ)|[Solution](../Solutions/python3/217-contains-duplicate.py )||[Solution](../Solutions/C/217-Contains-Duplicate.c)|
|1|[ Two Sum](https://leetcode.com/problems/two-sum/)|Easy|Array&Hashing|[video](https://www.youtube.com/watch?v=NNOXAtc2c_c&t=4s)|[Solution](../Solutions/python3/1-two-sum.py)||[Solution](../Solutions/C/1-Two-Sum.c)|
|58|[Length of Last Word](https://leetcode.com/problems/length-of-last-word/)|Easy|Array&Hashing||[Solution](../Solutions/python3/58.py)|[Solution](../Solutions/C++/58.%20Length%20of%20Last%20Word.cpp)|[Solution](../Solutions/C/58-Length-of-Last-Word.c)|
|217|[ Contains Duplicate](https://leetcode.com/problems/contains-duplicate/)|Easy|Array&Hashing|[Video](https://www.youtube.com/watch?v=zfRMonn79wQ)|[Solution](../Solutions/python3/217-contains-duplicate.py )|[Solution](../Solutions/C++/0217-contains-duplicate/0217-contains-duplicate.cpp)|[Solution](../Solutions/C/217-Contains-Duplicate.c)|
|1|[ Two Sum](https://leetcode.com/problems/two-sum/)|Easy|Array&Hashing|[video](https://www.youtube.com/watch?v=NNOXAtc2c_c&t=4s)|[Solution](../Solutions/python3/1-two-sum.py)|[Solution](../Solutions/C++/0001-two-sum/0001-two-sum.cpp)|[Solution](../Solutions/C/1-Two-Sum.c)|
|27|[Remove Element](https://leetcode.com/problems/remove-element/)|Easy|Array&Hashing||[Solution](../Solutions/python3/27.py) | [Solution](../Solutions/C++/27.Remove-Element.cpp)|[Solution](../Solutions/C/27-Remove-Element.c)|
|724|[Find Pivot Index](https://leetcode.com/problems/find-pivot-index/)|Easy|Array&Hashing||[Solution](../Solutions/python3/724.py)||[Solution](../Solutions/C/724-Find-Pivot-Index.c)|
|724|[Find Pivot Index](https://leetcode.com/problems/find-pivot-index/)|Easy|Array&Hashing||[Solution](../Solutions/python3/724.py)|[Solution](../Solutions/C++/724.%20Find%20Pivot%20Index.cpp)|[Solution](../Solutions/C/724-Find-Pivot-Index.c)|
|448|[Find All Numbers Disappeared in an Array](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/)|Easy|Array&Hashing||[Solution](../Solutions/python3/448.py) | [Solution](../Solutions/C++/448.%20Find%20All%20Numbers%20Disappeared%20in%20an%20Array.cpp)|[Solution](../Solutions/C/448-Find-All-Numbers-Disappeared-in-an-Array.c)|
|118|[Pascal's Triangle](https://leetcode.com/problems/pascals-triangle/)|Easy|Array&Hashing||[Solution](../Solutions/python3/118.py) |
|242|[ Valid Anagram](https://leetcode.com/problems/valid-anagram/)|Easy|Array&Hashing||[Solution](../Solutions/python3/242-valid-anagram.py) |
|242|[ Valid Anagram](https://leetcode.com/problems/valid-anagram/)|Easy|Array&Hashing||[Solution](../Solutions/python3/242-valid-anagram.py) |[Solution](../Solutions/C++/0242-valid-anagram/0242-valid-anagram.cpp)
|392|[Is Subsequence](https://leetcode.com/problems/is-subsequence/)|Easy|Array&Hashing||[Solution](../Solutions/python3/392-Is-Subsequence.py) |
|14|[ Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/)|Easy|Array&Hashing||[Solution](../Solutions/python3/14-Longest-Prefix.py) | [Solution](../Solutions/C++/14.%20Longest%20Common%20Prefix.cpp)
|929|[Unique Email Addresses](https://leetcode.com/problems/unique-email-addresses/)|Easy|Array&Hashing||[Solution](../Solutions/python3/929-Unique-Email.py) |
|205|[Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings/)|Easy|Array&Hashing||[Solution](../Solutions/python3/205-Isomorphic-Strings.py) |
|605|[Can Place Flowers](https://leetcode.com/problems/can-place-flowers/)|Easy|Array&Hashing|[Video](https://www.youtube.com/watch?v=ciQA2TZVr4U)|[Solution](../Solutions/python3/605-Can-Place-Flowers.py) |
|605|[Can Place Flowers](https://leetcode.com/problems/can-place-flowers/)|Easy|Array&Hashing|[Video](https://www.youtube.com/watch?v=ciQA2TZVr4U)|[Solution](../Solutions/python3/605-Can-Place-Flowers.py) | [Solution](../Solutions/C++/0605-can-place-flowers/0605-can-place-flowers.cpp)
|169|[Majority Element](https://leetcode.com/problems/majority-element/)|Easy|Array&Hashing||[Solution](../Solutions/python3/169-Majority-Element.py) |
|496|[Next Greater Element I](https://leetcode.com/problems/next-greater-element-i/)|Easy|Array&Hashing||[Solution](../Solutions/python3/496-Next-Greater-Element.py) |
|1189|[Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons/)|Easy|Array&Hashing||[Solution](../Solutions/python3/1189.py) | [Solution](../Solutions/C++/1189.%20Maximum%20Number%20of%20Balloons.cpp)
|1299|[ Replace Elements with Greatest Element on Right Side](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side/)|Easy|Array&Hashing||[Solution](../Solutions/python3/1299.py) |
|290|[ Word Pattern](https://leetcode.com/problems/word-pattern/)|Easy|Array&Hashing||[Solution](../Solutions/python3/290-Word-Pattern.py) |
|347|[Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/)|Medium|Array&Hashing|[Video](https://www.youtube.com/watch?v=DvAE0cNiH9k&t=4s)|[Solution](../Solutions/python3/347-K-frequent.py)
|49|[ Group Anagrams](https://leetcode.com/problems/group-anagrams/)|Medium|Array&Hashing|[video](https://www.youtube.com/watch?v=AeVDUx25AFo&t=2s)|[Solution](../Solutions/python3/49-Group-anagrams.py) |
|49|[ Group Anagrams](https://leetcode.com/problems/group-anagrams/)|Medium|Array&Hashing|[video](https://www.youtube.com/watch?v=AeVDUx25AFo&t=2s)|[Solution](../Solutions/python3/49-Group-anagrams.py) | [Solution](../Solutions/C++/0049-group-anagrams/0049-group-anagrams.cpp)
|238|[ Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/)|Medium|Array&Hashing|[video](https://www.youtube.com/watch?v=NU8iBPcRR6w)|[Solution](../Solutions/python3/238-Product-except.py) |
|75|[ Sort Colors](https://leetcode.com/problems/sort-colors/)|Medium|Array&Hashing||[Solution](../Solutions/python3/75-Sort-Colors.py) |
|128|[Longest Consecutive Sequence ](https://leetcode.com/problems/longest-consecutive-sequence/)|Medium|Array&Hashing||[Solution](../Solutions/python3/128-longest-sequence.py) |
Expand Down
18 changes: 18 additions & 0 deletions Solutions/C++/58. Length of Last Word.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public:
int lengthOfLastWord(string s) {
int i = s.size() - 1;
int LastWordLength = 0;
for(i = i; i > -1; i--){
if(s[i] == ' '){
if(LastWordLength == 0)
continue;
else
break;
}
else
LastWordLength++;
}
return LastWordLength;
}
};
16 changes: 16 additions & 0 deletions Solutions/C++/724. Find Pivot Index.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public:
int pivotIndex(vector<int>& nums) {
int TotalSum = accumulate(nums.begin(),nums.end(),0);
int RightSum = 0, LeftSum = 0;
for(int i = 0; i < nums.size();i++){
if(i > 0){
LeftSum+= nums[i-1];
}
RightSum = TotalSum - nums[i] - LeftSum;
if(LeftSum == RightSum)
return i;
}
return -1;
}
};