From 9e58a77df02f27c4d3b1aa373cf48bee6bb660d8 Mon Sep 17 00:00:00 2001 From: Powerstot <77142630+Powerstot@users.noreply.github.com> Date: Wed, 12 May 2021 20:30:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A00344.=E5=8F=8D=E8=BD=AC?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=20Java=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加0344.反转字符串 Java版本 --- problems/0344.反转字符串.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/problems/0344.反转字符串.md b/problems/0344.反转字符串.md index ddb9805d..02282355 100644 --- a/problems/0344.反转字符串.md +++ b/problems/0344.反转字符串.md @@ -140,7 +140,21 @@ public: Java: - +```Java +class Solution { + public void reverseString(char[] s) { + int l = 0; + int r = s.length - 1; + while (l < r) { + s[l] ^= s[r]; //构造 a ^ b 的结果,并放在 a 中 + s[r] ^= s[l]; //将 a ^ b 这一结果再 ^ b ,存入b中,此时 b = a, a = a ^ b + s[l] ^= s[r]; //a ^ b 的结果再 ^ a ,存入 a 中,此时 b = a, a = b 完成交换 + l++; + r--; + } + } +} +``` Python: