Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b48d193

Browse files
Merge pull request doocs#264 from J-Cod3r/master
add Check Permutation java solution
2 parents f2ef4ec + c3950ab commit b48d193

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

‎lcci/01.02.Check Permutation/README.md‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff 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
### ...

‎lcci/01.02.Check Permutation/README_EN.md‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff 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
### ...
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /