Why is it faster to pass string by reference then by value?

Правка en3, от PrasoonJha, 2022-04-09 15:28:19

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.

Теги memoization, c++, recursion, pallindrome, string

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский PrasoonJha 2022-04-09 15:28:19 5 Tiny change: 'ubmitting one my solutions in leetco' -> 'ubmitting my solution in leetco'
en2 Английский PrasoonJha 2022-04-09 15:27:38 148
en1 Английский PrasoonJha 2022-04-09 15:19:14 340 Initial revision (published)