I am very interested in an apartment in Germany.
But the land lords want 3 years contract with me.
They say it is minimum. Is this legal?
There is no provision in Germany that a renting contract must cover a certain length. It is entirely possile to agree on a contract for one month or even less. (However, it may be impractical for both parties for a number of reasons.) This is based on freedom of contracts: unless there is another law specifying exceptions you are free to agree on contracts of any terms with any person (and you are free to refuse any contract).
In your case, it seems the landlord wants to rent out the flat for at least three years. They are entirely entitled to do so — as the comments stated, minimum length contracts are legal if the minimum length does not exceed four years. It is their flat and within the legal boundaries they can rent it out as they please.
Note that this is typically indeed a minimal length contract — not to be confused with a fixed-length contract. At the end of the three years the contract automatically extends indefinitely. However, you can terminate it at three month’s notice. This is unless the contract explicitly states that after three years the flat has to be returned.
It can be tough finding flats in Germany but unfortunately that’s the way it is.