Skip to content

Commit ecdaf39

Browse files
authored
wilderness, where she hath a place prepared of God
And the woman fled into the wilderness, where she hath a place prepared of God, that they should feed her there a thousand two hundred and threescore days. (Revelation 12:6)
1 parent 5d11b19 commit ecdaf39

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
//And the woman fled into the wilderness, where she hath a place prepared of God, that they should feed her there a thousand two hundred and threescore days. (Revelation 12:6)
3+
4+
package com.javarush.task.task39.task3908;
5+
6+
/*
7+
Возможен ли палиндром?
8+
*/
9+
public class Solution {
10+
public static void main(String[] args) {
11+
12+
}
13+
14+
public static boolean isPalindromePermutation(String s) {
15+
if (s == null || s.length() == 0) {
16+
return true;
17+
}
18+
s = s.toLowerCase();
19+
s = s.replaceAll(" ", "");
20+
boolean[] isOdd = new boolean[256];
21+
22+
for (int i = 0; i < s.length(); i++) {
23+
isOdd[s.charAt(i)] = !isOdd[s.charAt(i)];
24+
}
25+
26+
int numberOdds = 0;
27+
28+
for (int i = 0; i < isOdd.length; i++) {
29+
if (isOdd[i]) {
30+
numberOdds++;
31+
}
32+
if (numberOdds > 1) {
33+
return false;
34+
}
35+
}
36+
return true;
37+
}
38+
}
39+
40+
/*
41+
Возможен ли палиндром?
42+
43+
Реализуй метод isPalindromePermutation(String s) который будет возвращать true, если из всех символов строки s можно составить палиндром. Иначе - false.
44+
45+
46+
47+
Символы в анализируемой строке ограничены кодировкой ASCII.
48+
49+
Регистр букв не учитывается.
50+
51+
52+
53+
54+
55+
Требования:
56+
57+
1. Метод isPalindromePermutation должен возвращать true, если выполнив перестановку символов входящей строки можно получить палиндром.
58+
59+
2. Метод isPalindromePermutation должен возвращать false, если выполнив перестановку символов входящей строки получить палиндром невозможно.
60+
61+
3. Метод isPalindromePermutation должен быть публичным.
62+
63+
4. Метод isPalindromePermutation должен быть статическим.
64+
*/

0 commit comments

Comments
 (0)