PrasoonJha's blog

By PrasoonJha, history, 2 years ago, In English

When i was submitting my solution in leetcode, I was getting TLE when passing string by value but after changing it to string by reference it got faster. I thought strings were passes by refence automatically anyways. Below are images of code being accepted and not accepted.

  • Vote: I like it
  • -12
  • Vote: I do not like it

| Write comment?
»
2 years ago, # |
  Vote: I like it +15 Vote: I do not like it

Reference passes the same copy of the dp array. Pass by value creates new dp array each time the function is called. So, it takes more time and memory.