We cannot be sure if Noah was the only righteous man left, but still:
The sons of God saw that the daughters of mankind were beautiful, and they took any they chose as wives for themselves. And the Lord said, “My Spirit will not remain with mankind forever, because they are corrupt. Their days will be 120 years.” The Nephilim were on the earth both in those days and afterward, when the sons of God came to the daughters of mankind, who bore children to them. They were the powerful men of old, the famous men. When the Lord saw that man’s wickedness was widespread on the earth and that every scheme his mind thought of was nothing but evil all the time,
Genesis 6:2-5 Holman Christian Standard Bible
- All peoples' lives were eventually shortened, not just some who were wicked
Now the earth was corrupt in God’s sight, and the earth was filled with wickedness. God saw how corrupt the earth was, for every creature had corrupted its way on the earth.
Genesis 6:11-12 Holman Christian Standard Bible
Translations of Genesis 6:9
This is the history of the generations of Noah. Noah was a just and righteous man, blameless in his [evil] generation; Noah walked [in habitual fellowship] with God.
Amplified Bible, Classic Version
These are the generations of Noah: Noah was a just man and perfect in his generations, and Noah walked with God.
King James Version
- "Perfect in his generations" likely meant that there was no "sons of God" pollution in his line
This is the family history [2:4] of Noah. Noah was a ·good [righteous; just] man, the most ·innocent [blameless; Job 1:1] man of his ·time [generation], and he walked with God [5:24].
Expanded Bible
- The Job 1:1 reference for "blameless" is: that man was perfect and upright, and one that feared God, and eschewed evil -KJV
So it is likely that Noah's "Walked with God" relationship, blameless and righteous character, and genetic history free of the evil that plagued others caused him to find (not earn) grace in God's eyes.
There is a very thorough analysis of this idea at
https://enduringword.com/bible-commentary/genesis-6/