Skip to content

Commit 8990981

Browse files
authoredOct 26, 2020
add solution to move zeroes leetcode problem (#126)
* add solution to move zeroes lc problem * update readme (add profile links to contributors list)
1 parent 90e854c commit 8990981

File tree

2 files changed

+56
-29
lines changed

2 files changed

+56
-29
lines changed
 

Diff for: ‎C++/Move-Zeroes.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
//Problem Statement: Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.
3+
4+
//Solution:
5+
class Solution {
6+
public:
7+
void moveZeroes(vector<int>& nums) {
8+
int i = 0;
9+
for (int j = 0; j < nums.size(); j++) {
10+
// Bring all non zero numbers to the start of the array
11+
if (nums[j] != 0) {
12+
nums[i++] = nums[j];
13+
}
14+
}
15+
16+
while(i<nums.size()){
17+
nums[i++] = 0;
18+
}
19+
}
20+
};
21+
22+
// Time Complexity: O(n)
23+
// Space Complexity: O(n)

Diff for: ‎README.md

+33-29
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
124124
| 189 | [Rotate-Array](https://leetcode.com/problems/rotate-array/) | [Python](./Python/rotate-array.py) | O(N) | O(1) | Medium | Array |
125125
| 496 | [next-greater-element-i](https://leetcode.com/problems/next-greater-element-i) | [Python](./Python/496_nextgreaterelement.py) | O(N) | O(1) | Medium | Array |
126126
| 1470 | [Shuffle the Array](https://leetcode.com/problems/shuffle-the-array) | [Java](./Java/shuffle-the-array.java) | O(N) | O(1) | Easy | Array |
127+
| 283 | [Move-Zeroes](https://leetcode.com/problems/move-zeroes/) | [C++](./C++/Move-Zeroes.cpp) | O(N) | O(1) | Easy | Array |
127128

128129
<br/>
129130
<div align="right">
@@ -373,8 +374,10 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
373374
| 947 | [Most Stones Removed with Same Row or Column](https://leetcode.com/problems/most-stones-removed-with-same-row-or-column/) | [C++](./C++/Most-Stones-Removed-with-Same-Row-or-Column.cpp) | _O(V)_ | _O(2V)_ | Medium | Graph | Union Find | | [C++](./C++/Most-Stones-Removed-with-Same-Row-or-Column.cpp) | _O(V)_ | _O(2V)_ | Medium | Graph | Union Find |
374375
| 210 | [Course Schedule II](https://leetcode.com/problems/course-schedule-ii/) | [C++](./C++/Course-Schedule-II.cpp) | _O(V+E)_ | _O(V)_ | Medium | Graph | BFS |
375376
| 1627 | [Graph Connectivity with Threshold](https://leetcode.com/problems/graph-connectivity-with-threshold/) | [Java](./Java/graph_connectivity_with_threshold.java) | _O(V.logV + Q)_ | _O(V)_ | Hard | Graph | Union Find + Sieve |
376-
| 1631 | [Path with Minimum Effort](https://leetcode.com/problems/path-with-minimum-effort/) | [Java](./Java/path-with-minimum-effort.java) | _O(V^2)_ | _O(V)_ | Medium | Graph | Dijkstra's Shortest Path |
377+
| 1631 | [Path with Minimum Effort](https://leetcode.com/problems/path-with-minimum-effort/) | [Java](./Java/path-with-minimum-effort.java) | _O(V^2)_ | _O(V)_ | Medium | Graph | Dijkstra's Shortest Path |
378+
377379
<br/>
380+
378381
<div align="right">
379382
<b><a href="#algorithms">⬆️ Back to Top</a></b>
380383
</div>
@@ -410,34 +413,35 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if
410413

411414
## Contributors
412415

413-
| Name | Country | Programming Language | Where to find you<br><sup>(add all links to your profiles eg on Hackerrank, Codechef, LeetCode...)</sup> |
414-
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
415-
| [Gourav R](https://github.com/GouravRusiya30/) <br> <img src="https://github.com/GouravRusiya30.png" width="100" height="100"> | India | Java | [codedecks](https://www.youtube.com/c/codedecks/) <br> [Hackerrank](https://www.hackerrank.com/gouravrusiya786) <br> [LeetCode](https://leetcode.com/rusiya/) |
416-
| [Dima Vishnevetsky](https://github.com/dimshik100) <br> <img src="https://github.com/dimshik100.png" width="100" height="100"> | Israel | JavaScript | [Twitter](https://twitter.com/dimshik100) <br> [Facebook](https://www.facebook.com/dimshik) |
417-
| [Anuj Sharma](https://github.com/Optider/) <br> <img src="https://github.com/Optider.png" width="100" height="100"> | India | Python | [Github](https://github.com/Optider) |
418-
| [Lokendra Bohra](https://github.com/lokendra1704/) <br> <img src="https://github.com/lokendra1704.png" width="100" height="100"> | India | Python | [Leetcode](https://t.co/u0OByxhcHA) <br> [Hackerrank](https://www.hackerrank.com/lokendra17) |
419-
| [Yuri Spiridonov](https://github.com/YuriSpiridonov) <br> <img src="https://github.com/YuriSpiridonov.png" width="100" height="100"> | Russia | Python | [Twitter](https://twitter.com/YuriSpiridonov)<br>[Leetcode](https://leetcode.com/yurispiridonov/)<br>[Hackerrank](https://www.hackerrank.com/YuriSpiridonov) |
420-
| [Naveen Kashyap](https://github.com/naveenkash) <br> <img src="https://github.com/naveenkash.png" width="100" height="100"> | India | Javascript | [Twitter](https://twitter.com/naveen_kashyapp)<br>[Leetcode](https://leetcode.com/naveenkash/) |
421-
| [Rudra Mishra](https://github.com/Rudra407) <br> <img src="https://github.com/Rudra407.png" width="100" height="100"> | India | C++ | [Twitter](https://twitter.com/ruDra_Mishra407)<br>[Leetcode](https://leetcode.com/rudramishra/) |
422-
| [Sachin Singh Negi](https://github.com/sachinnegi) <br> <img src="https://github.com/sachinnegi.png" width="100" height="100"> | India | Python | [Twitter](https://twitter.com/SachinSinghNe17)<br>[Leetcode](https://leetcode.com/negisachin688/)<br>[Hackerrrak](https://www.hackerrank.com/negisachin688) |
423-
| [Girish Thatte](https://github.com/girishgr8/) <br> <img src="https://github.com/girishgr8.png" width="100" height="100"> | India | Java | [Leetcode](https://leetcode.com/girish13/) <br> [Hackerrank](https://www.hackerrank.com/procoder_13) <br> [Codechef](https://www.codechef.com/procoder_13) |
424-
| [Kevin Chittilapilly](https://github.com/KevinChittilapilly) <br> <img src="https://github.com/KevinChittilapilly.png" width="100" height="100"> | India | Java | [Leetcode](https://leetcode.com/being_kevin/) <br> [Hackerrank](https://www.hackerrank.com/ckevinvarghese11) <br> [Kaggle](https://www.kaggle.com/kevinchittilapilly) |
425-
| [Nour Grati](https://github.com/Nour-Grati) <br> <img src="https://github.com/Nour-Grati.png" width="100" height="100"> | Tunisia | Python | [Leetcode](https://leetcode.com/nourgrati/) <br> [Hackerrank](https://www.hackerrank.com/noor_grati) <br> [Twitter](https://twitter.com/GratiNour1) |
426-
| [Avinash Trivedi](https://github.com/trivediavinash) <br> <img src="https://github.com/trivediavinash.png" width="100" height="100"> | India | C++ | [Leetcode](https://leetcode.com/avi_002/) |
427-
| [Ishika Goel](https://github.com/ishikagoel5628) <br> <img src="https://github.com/Nour-Grati.png" width="100" height="100"> | India | C++ | [Leetcode](https://leetcode.com/ishikagoel5628/) |
428-
| [Fenil Dobariya](https://github.com/ifenil) <br> <img src="https://rb.gy/iascx3" width="100" height="100"> | India | Java | [Github](https://github.com/ifenil) |
429-
| [Prashansa Tanwar](https://github.com/prashansatanwar) <br> <img src="https://github.com/prashansatanwar.png" width="100" height="100"> | India | C++ | [Leetcode](https://leetcode.com/prashansaaa/) |
430-
| [Ishu Raj](https://github.com/ir2010) <br> <img src="https://github.com/ir2010.png" width="100" height="100"> | India | C++ | [Leetcode](https://leetcode.com/ishuraj2010/) |
431-
| [Rakesh Bhadhavath](https://github.com/Revenge-Rakesh) <br> <img src="https://avatars2.githubusercontent.com/u/36032275?v=4" width="100" height="100"> | India | Java | [Leetcode](https://leetcode.com/goal_cracker/) |
432-
| [Tarun Singh](https://github.com/TarunSingh56) <br> <img src="https://avatars3.githubusercontent.com/u/25122604?s=400&u=d01f190e9a8c3790d408c38387c68b6bc9db2ea6&v=4" width="100" height="100"> | India | C++ | [Leetcode](https://leetcode.com/_tarun/) |
433-
| [Hardik Gupta](https://github.com/harrdy272) <br> <img src="https://avatars3.githubusercontent.com/u/42604986?s=460&u=609a0839312a620d3d658ef19e8eac1e226a6eb4&v=4" width="100" height="100"> | India | C++ | [codeforces](https://codeforces.com/profile/harrdy272) <br>[codechef](https://www.codechef.com/users/hardikg272) <br> [Hackerrank](https://www.hackerrank.com/hardikg272) <br> [LeetCode](https://leetcode.com/hardikg272/) |
434-
| [Jaseem ck](https://github.com/Jaseemck) <br> <img src="https://github.com/Optider.png" width="100" height="100"> | India | Python | [Github](https://github.com/Jaseemck) |
435-
| [Ilias Khan](https://github.com/IliasKhan) <br> <img src="https://avatars3.githubusercontent.com/u/26863936?s=460&u=4501ffba5efd1a7b978416e8e434dff599c85384&v=4" width="100" height="100"> | India | C++ | [codechef](https://www.codechef.com/users/iliaskhan) <br> [Hackerrank](ckerrank.com/iliaskhan57) <br> [LeetCode](https://leetcode.com/ilias_khan/) <br> [codeforces](http://codeforces.com/profile/iliaskhan) |
436-
| [Shamoyeeta Saha](https://github.com/Shamoyeeta) <br> <img src="https://i.pinimg.com/236x/dc/ef/3a/dcef3abedf0e0761203aaeb85886a6f3--jedi-knight-open-source.jpg" width="100" height="100"> | India | C++ | [Hackerrank](https://www.hackerrank.com/sahashamoyeeta) <br> [Github](https://github.com/Shamoyeeta) |
437-
| [James Y](https://github.com/jameszu) <br> <img src="https://avatars0.githubusercontent.com/u/41566813?s=400&u=af77d15517566ea590a316030b4a6d402b0041b6&v=4" width="100" height="100"> | New Zealand | python | [Github](https://github.com/jameszu) |
438-
| [Hamza B](https://github.com/9Hamza) <br> <img src="https://avatars2.githubusercontent.com/u/56516922?s=400&u=2c1adeef0194a2859361d464f28783bfba698638&v=4" width="100" height="100"> | Saudi Arabia | Java | [Github](https://github.com/9Hamza) |
439-
| [Meli Haktas](https://github.com/MercerFrey) <br> <img src="https://avatars1.githubusercontent.com/u/29127873?s=460&u=149319db4468ec2316e49a75eb5e05b35eb05eef&v=4" width="100" height="100"> | Turkey | python | [Github](https://github.com/MercerFrey) |
440-
| [Saurav Prateek](https://github.com/SauravP97) <br> <img src="https://avatars3.githubusercontent.com/u/26816418?s=460&u=4b5222d5b6db79389efba062714c9dfba263732f&v=4" width="100" height="100"> | India | Java | [Github](https://github.com/SauravP97) <br> [Codechef](https://www.codechef.com/users/srvptk) <br> [Codeforces](https://codeforces.com/profile/srvptk97) <br> [Leetcode](https://leetcode.com/srvptk97) | |
416+
| Name | Country | Programming Language | Where to find you<br><sup>(add all links to your profiles eg on Hackerrank, Codechef, LeetCode...)</sup> |
417+
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
418+
| [Gourav R](https://github.com/GouravRusiya30/) <br> <img src="https://github.com/GouravRusiya30.png" width="100" height="100"> | India | Java | [codedecks](https://www.youtube.com/c/codedecks/) <br> [Hackerrank](https://www.hackerrank.com/gouravrusiya786) <br> [LeetCode](https://leetcode.com/rusiya/) |
419+
| [Dima Vishnevetsky](https://github.com/dimshik100) <br> <img src="https://github.com/dimshik100.png" width="100" height="100"> | Israel | JavaScript | [Twitter](https://twitter.com/dimshik100) <br> [Facebook](https://www.facebook.com/dimshik) |
420+
| [Anuj Sharma](https://github.com/Optider/) <br> <img src="https://github.com/Optider.png" width="100" height="100"> | India | Python | [Github](https://github.com/Optider) |
421+
| [Lokendra Bohra](https://github.com/lokendra1704/) <br> <img src="https://github.com/lokendra1704.png" width="100" height="100"> | India | Python | [Leetcode](https://t.co/u0OByxhcHA) <br> [Hackerrank](https://www.hackerrank.com/lokendra17) |
422+
| [Yuri Spiridonov](https://github.com/YuriSpiridonov) <br> <img src="https://github.com/YuriSpiridonov.png" width="100" height="100"> | Russia | Python | [Twitter](https://twitter.com/YuriSpiridonov)<br>[Leetcode](https://leetcode.com/yurispiridonov/)<br>[Hackerrank](https://www.hackerrank.com/YuriSpiridonov) |
423+
| [Naveen Kashyap](https://github.com/naveenkash) <br> <img src="https://github.com/naveenkash.png" width="100" height="100"> | India | Javascript | [Twitter](https://twitter.com/naveen_kashyapp)<br>[Leetcode](https://leetcode.com/naveenkash/) |
424+
| [Rudra Mishra](https://github.com/Rudra407) <br> <img src="https://github.com/Rudra407.png" width="100" height="100"> | India | C++ | [Twitter](https://twitter.com/ruDra_Mishra407)<br>[Leetcode](https://leetcode.com/rudramishra/) |
425+
| [Sachin Singh Negi](https://github.com/sachinnegi) <br> <img src="https://github.com/sachinnegi.png" width="100" height="100"> | India | Python | [Twitter](https://twitter.com/SachinSinghNe17)<br>[Leetcode](https://leetcode.com/negisachin688/)<br>[Hackerrrak](https://www.hackerrank.com/negisachin688) |
426+
| [Girish Thatte](https://github.com/girishgr8/) <br> <img src="https://github.com/girishgr8.png" width="100" height="100"> | India | Java | [Leetcode](https://leetcode.com/girish13/) <br> [Hackerrank](https://www.hackerrank.com/procoder_13) <br> [Codechef](https://www.codechef.com/procoder_13) |
427+
| [Kevin Chittilapilly](https://github.com/KevinChittilapilly) <br> <img src="https://github.com/KevinChittilapilly.png" width="100" height="100"> | India | Java | [Leetcode](https://leetcode.com/being_kevin/) <br> [Hackerrank](https://www.hackerrank.com/ckevinvarghese11) <br> [Kaggle](https://www.kaggle.com/kevinchittilapilly) |
428+
| [Nour Grati](https://github.com/Nour-Grati) <br> <img src="https://github.com/Nour-Grati.png" width="100" height="100"> | Tunisia | Python | [Leetcode](https://leetcode.com/nourgrati/) <br> [Hackerrank](https://www.hackerrank.com/noor_grati) <br> [Twitter](https://twitter.com/GratiNour1) |
429+
| [Avinash Trivedi](https://github.com/trivediavinash) <br> <img src="https://github.com/trivediavinash.png" width="100" height="100"> | India | C++ | [Leetcode](https://leetcode.com/avi_002/) |
430+
| [Ishika Goel](https://github.com/ishikagoel5628) <br> <img src="https://github.com/Nour-Grati.png" width="100" height="100"> | India | C++ | [Leetcode](https://leetcode.com/ishikagoel5628/) |
431+
| [Fenil Dobariya](https://github.com/ifenil) <br> <img src="https://rb.gy/iascx3" width="100" height="100"> | India | Java | [Github](https://github.com/ifenil) |
432+
| [Prashansa Tanwar](https://github.com/prashansatanwar) <br> <img src="https://github.com/prashansatanwar.png" width="100" height="100"> | India | C++ | [Leetcode](https://leetcode.com/prashansaaa/) |
433+
| [Ishu Raj](https://github.com/ir2010) <br> <img src="https://github.com/ir2010.png" width="100" height="100"> | India | C++ | [Leetcode](https://leetcode.com/ishuraj2010/) |
434+
| [Rakesh Bhadhavath](https://github.com/Revenge-Rakesh) <br> <img src="https://avatars2.githubusercontent.com/u/36032275?v=4" width="100" height="100"> | India | Java | [Leetcode](https://leetcode.com/goal_cracker/) |
435+
| [Tarun Singh](https://github.com/TarunSingh56) <br> <img src="https://avatars3.githubusercontent.com/u/25122604?s=400&u=d01f190e9a8c3790d408c38387c68b6bc9db2ea6&v=4" width="100" height="100"> | India | C++ | [Leetcode](https://leetcode.com/_tarun/) |
436+
| [Hardik Gupta](https://github.com/harrdy272) <br> <img src="https://avatars3.githubusercontent.com/u/42604986?s=460&u=609a0839312a620d3d658ef19e8eac1e226a6eb4&v=4" width="100" height="100"> | India | C++ | [codeforces](https://codeforces.com/profile/harrdy272) <br>[codechef](https://www.codechef.com/users/hardikg272) <br> [Hackerrank](https://www.hackerrank.com/hardikg272) <br> [LeetCode](https://leetcode.com/hardikg272/) |
437+
| [Jaseem ck](https://github.com/Jaseemck) <br> <img src="https://github.com/Optider.png" width="100" height="100"> | India | Python | [Github](https://github.com/Jaseemck) |
438+
| [Ilias Khan](https://github.com/IliasKhan) <br> <img src="https://avatars3.githubusercontent.com/u/26863936?s=460&u=4501ffba5efd1a7b978416e8e434dff599c85384&v=4" width="100" height="100"> | India | C++ | [codechef](https://www.codechef.com/users/iliaskhan) <br> [Hackerrank](ckerrank.com/iliaskhan57) <br> [LeetCode](https://leetcode.com/ilias_khan/) <br> [codeforces](http://codeforces.com/profile/iliaskhan) |
439+
| [Shamoyeeta Saha](https://github.com/Shamoyeeta) <br> <img src="https://i.pinimg.com/236x/dc/ef/3a/dcef3abedf0e0761203aaeb85886a6f3--jedi-knight-open-source.jpg" width="100" height="100"> | India | C++ | [Hackerrank](https://www.hackerrank.com/sahashamoyeeta) <br> [Github](https://github.com/Shamoyeeta) |
440+
| [James Y](https://github.com/jameszu) <br> <img src="https://avatars0.githubusercontent.com/u/41566813?s=400&u=af77d15517566ea590a316030b4a6d402b0041b6&v=4" width="100" height="100"> | New Zealand | python | [Github](https://github.com/jameszu) |
441+
| [Hamza B](https://github.com/9Hamza) <br> <img src="https://avatars2.githubusercontent.com/u/56516922?s=400&u=2c1adeef0194a2859361d464f28783bfba698638&v=4" width="100" height="100"> | Saudi Arabia | Java | [Github](https://github.com/9Hamza) |
442+
| [Meli Haktas](https://github.com/MercerFrey) <br> <img src="https://avatars1.githubusercontent.com/u/29127873?s=460&u=149319db4468ec2316e49a75eb5e05b35eb05eef&v=4" width="100" height="100"> | Turkey | python | [Github](https://github.com/MercerFrey) |
443+
| [Saurav Prateek](https://github.com/SauravP97) <br> <img src="https://avatars3.githubusercontent.com/u/26816418?s=460&u=4b5222d5b6db79389efba062714c9dfba263732f&v=4" width="100" height="100"> | India | Java | [Github](https://github.com/SauravP97) <br> [Codechef](https://www.codechef.com/users/srvptk) <br> [Codeforces](https://codeforces.com/profile/srvptk97) <br> [Leetcode](https://leetcode.com/srvptk97) |
444+
| [Anushka Verma](https://github.com/verma-anushka) <br> <img src="https://avatars0.githubusercontent.com/u/46157435?s=400&u=aa3db9cf25b4a9644a16607d0c8bd6c98763a62d&v=4" width="100" height="100"> | India | C++ | [Portfolio](https://verma-anushka.github.io/anushkaverma/) <br> [LeetCode](https://leetcode.com/anushka_verma/) |
441445

442446
<br/>
443447
<div align="right">

0 commit comments

Comments
 (0)
Please sign in to comment.