File tree Expand file tree Collapse file tree 3 files changed +36
-2
lines changed
lcci/01.02.Check Permutation Expand file tree Collapse file tree 3 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,18 @@ class Solution:
4141<!-- 这里可写当前语言的特殊实现逻辑 -->
4242
4343``` java
44-
44+ class Solution {
45+ public boolean checkPermutation (String s1 , String s2 ) {
46+ if (s1 == null || s2 == null || s1. length() != s2. length()) {
47+ return false ;
48+ }
49+ char [] c1 = s1. toCharArray();
50+ char [] c2 = s2. toCharArray();
51+ Arrays . sort(c1);
52+ Arrays . sort(c2);
53+ return Arrays . equals(c1, c2);
54+ }
55+ }
4556```
4657
4758### ...
Original file line number Diff line number Diff line change @@ -56,7 +56,18 @@ class Solution:
5656### Java
5757
5858``` java
59-
59+ class Solution {
60+ public boolean CheckPermutation (String s1 , String s2 ) {
61+ if (s1 == null || s2 == null || s1. length() != s2. length()) {
62+ return false ;
63+ }
64+ char [] c1 = s1. toCharArray();
65+ char [] c2 = s2. toCharArray();
66+ Arrays . sort(c1);
67+ Arrays . sort(c2);
68+ return Arrays . equals(c1, c2);
69+ }
70+ }
6071```
6172
6273### ...
Original file line number Diff line number Diff line change 1+ class Solution {
2+ public boolean CheckPermutation (String s1 , String s2 ) {
3+ if (s1 == null || s2 == null || s1 .length () != s2 .length ()) {
4+ return false ;
5+ }
6+ char [] c1 = s1 .toCharArray ();
7+ char [] c2 = s2 .toCharArray ();
8+ Arrays .sort (c1 );
9+ Arrays .sort (c2 );
10+ return Arrays .equals (c1 , c2 );
11+ }
12+ }
You can’t perform that action at this time.
0 commit comments