To me, the main idea of this story is that a person's attitude is what matters the most in life.
In the story, Johnsy is dying largely because she thinks she is dying. When her roommate tries to reason with her and treat her like an adult, Johnsy continues to fade toward death.
But when the old man paints the leaf on the wall, she becomes convinced that she is not going to die after all. Objectively speaking, nothing has changed. But she has convinced herself that she can live where before she had convinced herself that she would die.
The power of hope is the main idea of O. Henry's "The Last Leaf."
Hope is what threads through this moving story of the love that one young lady from New York has for another from California, along with the love from one grumpy little old man. The power of the hope that these characters hold onto throughout O. Henry's narrative acts as an antidote to Johnsy's deadly illness.
Sue tells Johnsy that her idea of dying when the last leaf falls is "nonsense" and makes an effort to change her friend's mind by giving her hope. She tells her to hold onto the words of the doctor, who has said that her chances are ten to one. Sue then draws down the curtain so that Johnsy will not watch the leaves.
Sue also solicits the assistance of Old Behrman, who cares deeply for Johnsy. He ensures that Johnsy will retain her hope of getting well by painting the ivy leaf on the wall of a building opposite her window because she has said she will die when the last leaf falls. When Johnsy sees the painted leaf, she is encouraged to get well with a renewed hope.