Margaret Hamilton, the Wicked Witch of the West who melted at the feet of Dorothy in the 1939 film classic "The Wizard of Oz," died of an apparent heart attack May 16 at the Noble Horizons nursing home here. She was 82.

Miss Hamilton worked as a character actress for more than 50 years and appeared in more than 75 films and scores of plays. She also had a five-year run as Cora, the kindly old storekeeper who appeared in commercials for Maxwell House coffee.

But she was best known for "Oz." Generations of children thrilled at her depiction of the green-skinned witch, and with each showing of the film on television she received hundreds of letters from young fans.

Her death leaves Ray Bolger, who played the Scarecrow, as the only surviving major cast member of the film. The others included Judy Garland as Dorothy, Jack Haley as the Tin Man, Bert Lahr as the Cowardly Lion and Billie Burke as Glinda the Good Witch.

In 1973, Miss Hamilton said she had turned down countless offers to re-create the role. "I suppose I've turned down a fortune, too, but I just don't want to spoil the magic. Little children's minds can't cope with seeing a mean witch alive again," she said.

"Many times, I see mothers and little children and the mothers always recognize me as the witch. Often, they say to the kids, 'Don't you know who she is? She's the witch in the 'Wizard of Oz!' Then the kids look disappointed and say, 'But I thought she melted.' It's as though they think maybe I'm going to go back and cause trouble for Dorothy again."

The celebrity Miss Hamilton enjoyed for chasing Dorothy down the Yellow Brick Road was ironic for two reasons. She was a former kindergarten teacher and loved children. And she never thought the witch was her best work.

But even as the evil witch, she was able to stir sympathy in her audience. Dorothy herself seemed horrified when she dashed water on the Wicked One and the witch slowly dissolved into a puddle of nothingness, moaning "What a world . . . what a world . . . . "

"I didn't mean to kill her!" Dorothy cried.

A native of Cleveland, Miss Hamilton first got a taste of the theater in a class production in high school. But she was trained to teach kindergarten, and went on to operate private schools in Cleveland and in Rye, N.Y.

In 1927, she became a member of the Cleveland Play House, which now sponsors a scholarship fund in her name. Her first part was in a play called "The Man Who Ate the Popomack." In three years, she performed 25 roles.

From there, she won a part in "Another Language," which played for a year on Broadway. She was hired to reprise her role in the film version in 1932, and that was the start of her Hollywood career.

She appeared in "My Little Chickadee" with W.C. Fields and Mae West, "State of the Union," "A Slight Case of Murder," "Nothing Sacred" and many others. As recently as 1971, she appeared in "Brewster McCloud" and "The Anderson Tapes."

The roles were not wide-ranging. Her face, with the distinctive bump on her nose, led to parts as smarmy gossips, spinsters and maids.

"I've done some hard-bitten parts, but most of the time I've been the cantankerous cook or the acidulous aunt with a corset of steel and a heart of gold," she once said.

Her marriage to Paul Meserve, a landscape architect, ended in divorce. Survivors include a son, Hamilton Meserve of Millbrook, N.Y.