Why is it faster to pass string by reference then by value?
Difference between en1 and en2, changed 148 character(s)
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.
↵
↵
![ ](/predownloaded/09/29/0929aaf1c5323a569c2c0f1b80177424a9f984f3.jpg)↵
![ ](/predownloaded/64/31/643150bdf9a12db0b77441497ccc99b4140aaba9.jpg)

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)