We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c4f4785 commit 2d6c164Copy full SHA for 2d6c164
palindromic-substrings/GangBean.java
@@ -0,0 +1,29 @@
1
+class Solution {
2
+ public int countSubstrings(String s) {
3
+ /**
4
+ 각 문자를 중간으로 갖는 palindrome 여부 체크
5
+ + 두개의 문자를 중간으로 갖는 palindrome 여부 체크
6
+ */
7
+ int count = 0;
8
+ int length = s.length();
9
+ for (int i = 0; i < length; i++) { // O(N)
10
+ int start = i;
11
+ int end = i;
12
+ while (0 <= start && end < length && start <= end && s.charAt(start) == s.charAt(end)) { // O(N)
13
+ count++;
14
+ start--;
15
+ end++;
16
+ }
17
+
18
+ start = i;
19
+ end = i + 1;
20
21
22
23
24
25
26
27
+ return count; // O(N^2)
28
29
+}
0 commit comments