본문 바로가기

열정가득한 개발자의 이야기/Javascript Algorithm

1071. Greatest Common Divisor of Strings (JS)

반응형

hi. 

I have another question about a LeetCode problem.

First, please check what the problem is.

It's quite a simple one, but it was hard to implement in code.

I'm not an AI, so it's really difficult to explain in a programming language.

I tried using the substr and includes methods,

but they didn't work properly.

They couldn't cover all the cases.

So... I googled the answer and re-realized the power of recursion.

The key is to keep dividing the elements until we find the same one.

The code on the right side is the correct one.

 

reference : https://mindevlog.tistory.com/254

반응형