Movatterモバイル変換


[0]ホーム

URL:


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

Commit35ab8e9

Browse files
add 1763
1 parent38291e5 commit35ab8e9

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1763|[Longest Nice Substring](https://leetcode.com/problems/longest-nice-substring/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1763.java)||Easy|String|
1112
|1759|[Count Number of Homogenous Substrings](https://leetcode.com/problems/count-number-of-homogenous-substrings/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1758.java)||Medium|String ,Greedy|
1213
|1758|[Minimum Changes To Make Alternating Binary String](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1758.java)||Easy|Greedy, Array|
1314
|1754|[Largest Merge Of Two Strings](https://leetcode.com/problems/largest-merge-of-two-strings/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1753.java)||Medium|Greedy, Suffix Array|
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_1763 {
4+
publicstaticclassSolution1 {
5+
publicStringlongestNiceSubstring(Strings) {
6+
Stringlongest ="";
7+
for (inti =0;i <s.length() -1;i++) {
8+
for (intj =i;j <=s.length();j++) {
9+
if (isNiceString(s.substring(i,j))) {
10+
if (longest.length() <j -i) {
11+
longest =s.substring(i,j);
12+
}
13+
}
14+
}
15+
}
16+
returnlongest;
17+
}
18+
19+
privatebooleanisNiceString(Stringstr) {
20+
int[]uppercount =newint[26];
21+
int[]lowercount =newint[26];
22+
for (charc :str.toCharArray()) {
23+
if (Character.isUpperCase(c)) {
24+
uppercount[Character.toLowerCase(c) -'a']++;
25+
}else {
26+
lowercount[c -'a']++;
27+
}
28+
}
29+
for (inti =0;i <uppercount.length;i++) {
30+
if (uppercount[i] >0 &&lowercount[i] >0 || (uppercount[i] ==0 &&lowercount[i] ==0)) {
31+
continue;
32+
}else {
33+
returnfalse;
34+
}
35+
}
36+
returntrue;
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp