aylei / leetcode-rust

my leetcode solutions in rust
Apache License 2.0
717 stars 141 forks source link

62 does not seem right to me #13

Closed zwhitchcox closed 4 years ago

zwhitchcox commented 4 years ago

The formula you gave seems incorrect to me. I know you said it's high school math, but I guess I forgot it.

It works, for the example, but I don't see how it could work for many other ones.

For example, say you have a 3x3 matrix. With your formula, it would be 3!/(3!*(3 - 3)!) = 1. It seems to me like there would be more than one way to make it down in a 3 by 3 matrix. In fact, matrix with the same number of rows and columns would equal 1 with the formula n! / r!(n-r)!.

Am I missing something here?

zwhitchcox commented 4 years ago

Ok, so, looking at your actual code (I got stuck trying to understand the formula), it looks like you're actually using the formula [(m + n)!/max(m,n)!]/min(m,n)!. So, I guess that was the problem.

aylei commented 4 years ago

@zwhitchcox Yes, sorry for not making it clearer, n denotes the total elements (m + n) in the formula.

zwhitchcox commented 4 years ago

No! Don't be sorry! Thanks so much for posting your solutions, they are very helpful to me.

It makes a lot more sense now :)...had to watch a few khan academy videos though

zwhitchcox commented 4 years ago

So, the actual formula would be (m+n)!/(n!*m!)

in case anyone else has trouble with this