这题确实easy,做这题倒真可以脱离IDE在leetcode编辑器里刷题了。
做这题,又犯了一次java与js字符串的小错误,在Java里获取String长度的length()是method,在js里获取字符串长度的length是property,老是搞混淆了。
Javascript
1 | /** |
Submission Detail
- 476 / 476 test cases passed.
- Your runtime beats 96.31 % of javascript submissions.
Java
LOOP+SB
1
1 | class Solution { |
Submission Detail
- 476 / 476 test cases passed.
- Your runtime beats 13.87 % of java submissions.
跟js写法差不多,这java代码的性能倒不行
2
1 | class Solution { |
Submission Detail
- 476 / 476 test cases passed.
- Your runtime beats 5.40 % of java submissions.
SB
1 | class Solution { |
Submission Detail
- 476 / 476 test cases passed.
- Your runtime beats 5.40 % of java submissions.
直接用StringBuilder的reverse(),用StringBuffer好像也类似,性能没什么变化
逆转字符数组
Ref
1 | class Solution { |
Submission Detail
- 476 / 476 test cases passed.
- Your runtime beats 7.62 % of java submissions.
Rust
1 | impl Solution { |
Submission Detail
- 478 / 478 test cases passed.
- Runtime: 20 ms, faster than 95.94% of Rust online submissions for Reverse String.
- Memory Usage: 5.1 MB, less than 100.00% of Rust online submissions for Reverse String.