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

Commit10885cb

Browse files
committed
Added 3 solutions
1 parent848c9ab commit10885cb

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

‎Easy/Letter Case Permutation.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
classSolution {
2+
publicList<String>letterCasePermutation(StringS) {
3+
List<String>ans =newArrayList<>();
4+
letterCasePermutationHelper(ans,S.toCharArray(),0);
5+
6+
returnans;
7+
}
8+
9+
privatevoidletterCasePermutationHelper(List<String>ans,char[]chars,intindex) {
10+
if (index ==chars.length) {
11+
ans.add(newString(chars));
12+
}
13+
else {
14+
if (Character.isLetter(chars[index])) {
15+
chars[index] =Character.toLowerCase(chars[index]);
16+
letterCasePermutationHelper(ans,chars,index+1);
17+
chars[index] =Character.toUpperCase(chars[index]);
18+
}
19+
20+
letterCasePermutationHelper(ans,chars,index+1);
21+
}
22+
}
23+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
classSolution {
2+
publicstaticint[]numberOfLines(int[]widths,StringS) {
3+
if (S.isEmpty()) {
4+
returnnewint[]{0,0};
5+
}
6+
7+
intcapacity =100;
8+
char[]chars =S.toCharArray();
9+
intcount =1;
10+
11+
for (charc :chars) {
12+
if (capacity -widths[c-'a'] <0) {
13+
capacity =100;
14+
count++;
15+
}
16+
capacity -=widths[c-'a'];
17+
}
18+
19+
returnnewint[]{count,100-capacity};
20+
}
21+
}

‎Medium/Contiguous Array.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
classSolution {
2+
publicintfindMaxLength(int[]nums) {
3+
Map<Integer,Integer>map =newHashMap<>();
4+
map.put(0, -1);
5+
intmaxLen =0;
6+
intcount =0;
7+
8+
for (inti=0;i<nums.length;i++) {
9+
count +=nums[i] ==0 ? -1 :1;
10+
if (map.containsKey(count)) {
11+
maxLen =Math.max(maxLen,i-map.get(count));
12+
}
13+
else {
14+
map.put(count,i);
15+
}
16+
}
17+
18+
returnmaxLen;
19+
}
20+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp