The TransCompilator

Solved LeetCode program · 817 of 1,000

#1071 · Greatest Common Divisor of Strings

Easy String chunk-17.md

Original English source

Keep a shared leftsize of 0. Keep a shared rightsize of 0.

To reduce.
Repeat while rightsize is more than 0.
The rest is leftsize modulo rightsize. Set leftsize to rightsize. Set rightsize to rest.

The first is "ABCABC". The second is "ABC". The joined is a copy of first. Place second into joined. The other is a copy of second. Place first into other. The firstlast is the last position of first. The secondlast is the last position of second. Set leftsize to firstlast plus 1. Set rightsize to secondlast plus 1. Reduce. The span is leftsize. The piece is the slice of first from 0 to span. The answer is a copy of piece. The empty is empty text. The same is 0. If joined matches other, set same to 1. If same is 0, set answer to empty. Show answer.

Open in Playground Browse all 1,000 problems

Expected stdout

ABC