Блог пользователя PrasoonJha

Автор PrasoonJha, история, 2 года назад, По-английски

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.

  • Проголосовать: нравится
  • -12
  • Проголосовать: не нравится

»
2 года назад, # |
  Проголосовать: нравится +15 Проголосовать: не нравится

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.