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

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

When i was submitting one my solutions 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)