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

Revision en1, by 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.

Tags memoization, c++, recursion, pallindrome, string

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English PrasoonJha 2022-04-09 15:28:19 5 Tiny change: 'ubmitting one my solutions in leetco' -> 'ubmitting my solution in leetco'
en2 English PrasoonJha 2022-04-09 15:27:38 148
en1 English PrasoonJha 2022-04-09 15:19:14 340 Initial revision (published)