In short no.
What you are describing is plain and simple a derived work. It can be 99.9% code that you have added, but because it is derived from some one elses code, you are still required to respect the copyright and license of the original code.
What other options do you have?
Can you look at that code, see how it works and then write your own version from scratch?
This is not so clear cut. However you are still at substantial risk of breaching copyright. If you copy any code verbatim It's a breach. If you cut and paste code and then rename the variables etc... It's a breach. If you copy a technique to solve a specific problem, writing new code as you go, that is still a breach of copyright.
If you look at the code and think that's how you use that function and then go off and write your own program from scratch without copying verbatim those two lines of code then you are probably the owner of your code.
To be 100% sure of owning my code, what doctor need to do?
The key is to avoid the risk of copyright claims in the first place. Do not look at copyrighted code for examples. So not write code when someone else (like your employer) could have a claim on your code). Use source control to log regular changes to the code. ( this proves you wrote it, and demonstrates the code development rather than you copied it wholesale) and do not reuse your code in an environment where the recipient has reason to believe they now own the code.
So why is everyone else talking about licenses?
Most code available on the Internet is available under license. That license allows you access to that code on terms that the code owner has chosen. How you can use that code and you entitlements and rights to the code are defined in the software license, and may entitle you to create derived works, to sell those for profit and to not have to give anyone your source code. Likewise it may not. It all depends on the license terms. However someone else owns the copyright to the original code and you cannot prevent them licensing that same code to your competitors.