Skip to content

Commit 546aa53

Browse files
committed
add move zero problem
1 parent 758edcc commit 546aa53

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This is my way of saying - change your interview style. There are lots of smart
1515
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1616
| [Unique binary search trees](https://leetcode.com/problems/unique-binary-search-trees/description/) | [click](https://github.com/sagivo/algorithms/blob/master/src/unique_bsts.rb) |
1717
| [House Robber](https://leetcode.com/problems/house-robber/description/) | [click](https://github.com/sagivo/algorithms/blob/master/src/house-robber.rb) |
18+
| [Decode Ways](https://leetcode.com/problems/decode-ways) | [click](https://github.com/sagivo/algorithms/blob/master/src/decode_ways.rb) |
1819
| [Coin change](https://leetcode.com/problems/coin-change/description/) | [click](https://github.com/sagivo/algorithms/blob/master/src/coin-change.rb) |
1920
| [Decode Strings](https://leetcode.com/problems/decode-string/description/) | [click](https://github.com/sagivo/algorithms/blob/master/src/decode_string.rb) |
2021
| [Wiggle Subsequence](https://leetcode.com/problems/wiggle-subsequence/description/) | [click](https://github.com/sagivo/algorithms/blob/master/src/wiggle_subsequence.rb) |
@@ -50,6 +51,7 @@ This is my way of saying - change your interview style. There are lots of smart
5051
| [Countingsort algorithm](http://en.wikipedia.org/wiki/Counting_sort) | [click](https://github.com/sagivo/algorithms/blob/master/src/counting_sort.rb) |
5152
| [Shellsort algorithm](http://en.wikipedia.org/wiki/Shellsort) | [click](https://github.com/sagivo/algorithms/blob/master/src/shell_sort.rb) |
5253
| [Knapsack problem](http://en.wikipedia.org/wiki/Knapsack_problem) | [click](https://github.com/sagivo/algorithms/blob/master/src/knapsack.rb), [click](https://github.com/sagivo/algorithms/blob/master/src/knapsack2.rb) |
54+
| [Move Zeroes](https://leetcode.com/problems/move-zeroes) | [click](https://github.com/sagivo/algorithms/blob/master/src/move_zeroes.rb) |
5355
| [Longest common subsequence problem](https://en.wikipedia.org/wiki/Longest_common_subsequence_problem) | [click](https://github.com/sagivo/algorithms/blob/master/src/longest_common_subsequence.rb) , [click](https://github.com/sagivo/algorithms/blob/master/src/longest_increasing_subsequence.rb) |
5456
| [Monty Hall Problem](https://en.wikipedia.org/wiki/Monty_hall_problem) | [click](https://github.com/sagivo/algorithms/blob/master/src/monty_hall.rb) |
5557
| [Eucliden and Extended Eucliden algorithm](http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm) | [click](https://github.com/sagivo/algorithms/blob/master/src/gcd.rb) |

move_zeroes.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# problem: https://leetcode.com/problems/move-zeroes
2+
# @param {Integer[]} nums
3+
# @return {Void} Do not return anything, modify nums in-place instead.
4+
def move_zeroes(nums)
5+
i = 0
6+
nums.each do |n|
7+
if n != 0
8+
nums[i] = n
9+
i += 1
10+
end
11+
end
12+
(i...nums.size).each {|indx| nums[indx] = 0}
13+
return nums
14+
end
15+
16+
p move_zeroes([0,1,0,3,12]) #=> [1,3,12,0,0]

0 commit comments

Comments
 (0)