-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
64 lines (41 loc) · 2.04 KB
/
Solution.java
File metadata and controls
64 lines (41 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//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)
package com.javarush.task.task39.task3908;
/*
Возможен ли палиндром?
*/
public class Solution {
public static void main(String[] args) {
}
public static boolean isPalindromePermutation(String s) {
if (s == null || s.length() == 0) {
return true;
}
s = s.toLowerCase();
s = s.replaceAll(" ", "");
boolean[] isOdd = new boolean[256];
for (int i = 0; i < s.length(); i++) {
isOdd[s.charAt(i)] = !isOdd[s.charAt(i)];
}
int numberOdds = 0;
for (int i = 0; i < isOdd.length; i++) {
if (isOdd[i]) {
numberOdds++;
}
if (numberOdds > 1) {
return false;
}
}
return true;
}
}
/*
Возможен ли палиндром?
Реализуй метод isPalindromePermutation(String s) который будет возвращать true, если из всех символов строки s можно составить палиндром. Иначе - false.
Символы в анализируемой строке ограничены кодировкой ASCII.
Регистр букв не учитывается.
Требования:
1. Метод isPalindromePermutation должен возвращать true, если выполнив перестановку символов входящей строки можно получить палиндром.
2. Метод isPalindromePermutation должен возвращать false, если выполнив перестановку символов входящей строки получить палиндром невозможно.
3. Метод isPalindromePermutation должен быть публичным.
4. Метод isPalindromePermutation должен быть статическим.
*/