Having researched this for the U.S. side of things, the short answer is yes, that's part of it being public domain. There are some notable things though:
The characters are still public domain, but the new story is copyrighted to the creator (in this case, you). Also, if the work has been in continuous production from time of creation until present, certain works may still be copyrighted and can create situations that lawyers could give you trouble for. As a general rule, new alterations to the original sources in public domain are not disregarded, but those derivatives are still under copyright to the creator of the derivative work. I can certainly tell a story about the Norse God Thor... but if I make him look like a blonde guy and fights crime, I'm going to hear from everyone's favorite mouse and his well paid lawyers. Speaking of him, current copyright law in the States lets things fall into the public domain after they've become 20 years older than present age of the first Mickey Mouse cartoon, "Steamboat Willie"... If this seems like a unobtainable goal since Steamboat Willie is nearing its centennial and nothing created today will ever be 20 years older than it, welcome to most public domain advocates' nightmares. Disney spends a lot of money on lobbying Congress to increase the length of copyright right around the same time Mickey's first appearance is about to fall into public domain (DC comics also engages in this when Superman is close as well, but since Mickey came out first, D.C. and its parent Company, Warner Brothers (a direct competitor with Disney) are more than happy to let Disney do the heavy lifting in this regards).
D.C. is another strange case in that it acquired rights to a lot of old superhero characters from the 40s that, unknown to anyone at the time of purchase, had already lapsed into public domain (the most famous is the character of Blue Beetle). D.C. gets around this by saying the current published characters are actually recipients of the mantle from the original character, which means that they are unique characters and D.C. can claim their rights. The original character is fair to use in anyway they see fit, but if you try to have him pace the mantle to a new person, now D.C. can sue you for copyright infringement because your product is close to theirs and they can argue you are making profits off of it.
Then there is the matter that got me to drop my public domain character project which is international concerns. With different laws, in different countries, you could potentially make a work that can't legally be sold in a country because the rights still belong to the owner in that country (For example, you cannot just make a Peter Pan derrivative, because the law in Britain specifically writes an exception for that specific work that the National Hospital System owns it (the rights were donated to a children's hospital that is now currently in the national system) and the government gave a special exemption from lapsing into public domain so the Hospital could recieve the funds from all works using the character. This will leave you open to lawsuit by the rights holder under that country's laws that may be honored by your own country if they have an interest in staying on the country's good side.
All this is contingent on the whether or not you intend to make money off the product. To prove that copyright infringement is happening, showing benefit from your product that would have gone to the right's holder is needed. If you just post it in a free area on the internet for all the world so choosing can view it, you're fine (there are a few hosting sights that, out of respect for the creator, do not allow the hosting of certain fan derivatives, but they aren't legally barred from doing so. It is important to note that in the U.S. a threat of a lawsuit is enough to force compliance because these things can get very out of hand very fast, so even if it's a legally empty threat, the right's holder usually can better absorb the cost before it gets anywhere near trial and the accused will just remove the content to avoid losing money.).
Now, this becomes even trickier if your derivative work is in the form of parody, satire, education, or review (there might be other information, but I'm not sure). You can use portions of the work freely as long as the benefit to doing them in such a way isn't a wholesale lift of the work (RiffTrax style things that are meant as fan commentary over the whole movie are generally sold as just the audio track and leave it up to the fan to get the visual component from the movie and some fan subs of foreign language works may add stylizations to recurring phrases (I am a fan of the Japanese Power Rangers equivalent, which usually stylizes the morphing calls in their subtitles) and then offer the episode for free and claim it's designed to help people who want to learn Japanese by providing fairly accurate translations of something that will likely be consumed by a child who will have a poor grasp of the language anyway... this isn't always smiled upon.
Again, be careful. Youtube got into some trouble last year when it came out that several popular internet reviewers were losing a lot of monetization because YouTube's complaint system unfairly favored the right's holder and in some cases would allow the rights holder to claim all money the film made while the video was being disputed, regardless of outcome. Again, this was Youtube trying to avoid a suit by giving the person threatening one what they wanted. This is why famous parody musician Weird Al Yankovic asked permission from the person whose work he intends to parody... he was famous enough for his music that by the early 90s, several bands consider it a mark of success in the industry when Weird Al comes a knocking. There is no legal reason for him to do this, he just wants to make sure there are no hard feelings. One of the few people who refused him a song was his earliest celebrity fan, Michael Jackson (who had been so impressed by the result of Weird Al's first parody he lent the guy the set and crew for the music video for the original so that Al could do a parody music video). Jackson requested that Al not do a parody of "Black and White" that was planned because Jackson didn't want to belittle the message of racial tolerance the song was promoting. Still, he supported every other parody of him. Similarly the famous kerfuffle with Coolio over Al's Gangster's Paradise parody resulted when Al contacted the record label who said yes because they had no legal way to stop Al and Al thought he had received blessing from Coolio, who was outraged when he learned the song was made without his consent. (He would later admit that, in light of the misunderstanding, he still enjoyed the resulting song and was impressed that Al could rap.) In a more recent incident, Al almost scrapped a parody of Lady Gaga because her agent denied the request (upon learning the request was made, Gaga personally called Al to override the agent, who wasn't aware Gaga was a huge fan of Al's and she has said such a request was probably one of the biggest honors she received in the music industry up to that point). At no point in all of this was Al in legal trouble, it was merely part of his own personal morality and code that was violate.
One fun fact, the reason why English speaking theaters consider Shakespeare's play Macbeth to be cursed is because it's a reliable fallback production in case the theater can't do another play (in addition to being short of Shakespeare's plays, it's iconic, requires little in the way of sets or props (even by Shakespeare's spartan standards) most of which exist already in a common theater house and above all, nobody has to pay the bard royalties to do it). It's cursed because, if it's being put on, there's a good chance something's already gone wrong.
So in review, there is nothing generally wrong with doing a rewrite of the ending and selling it as your own work for profit. I would do some research into the status of your work in the public domain and check for any other derrivative works that might have done something similar. You don't have to read that work (especially recomended... can't steal someones idea if you never had contact with it to begin with) but if the generic description rings too close to your idea, tread lightly.