Skip to content

Conversation

@dnsanche
Copy link

@dnsanche dnsanche commented Nov 14, 2019

Better something than nothing...

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right something is better than nothing. You don't have many methods here, but factorial and reverse_in_place are well done.

# Space complexity: ?
# Time complexity: O(n), because of the size of the stack (number of methods that is accumulated in the stack to run)
# Space complexity: O(n), because of the size of this stack
def factorial(n)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +20 to +27
while i < j
memo = s[i]
s[i] = s[j]
s[j] = memo

i += 1
j -= 1
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A while loop, this is supposed to be recursive method 🤔

# Time complexity: O(n) ~ n/2 as increasing and decreasing both pointer in same call
# Space complexity: O(n), n/2 recursive calls,
# because both pointers are moving each time the method is called
def reverse_inplace(s, i = 0, j = s.length - 1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants