Skip to content

Commit 30294df

Browse files
committed
Problems 14,58
0 parents  commit 30294df

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package me.darksnakex.problems;
2+
3+
public class p14 {
4+
5+
public String longestCommonPrefix(String[] strs) {
6+
7+
StringBuilder res = new StringBuilder();
8+
if(strs.length==1 || strs[0].isEmpty()){
9+
return strs[0];
10+
}
11+
12+
String palabra = strs[0];
13+
14+
int j = 0;
15+
for(int i = 1; i < strs.length; i++){
16+
if(j >= palabra.length() || j >= strs[i].length() || palabra.charAt(j) != strs[i].charAt(j)){
17+
break;
18+
}
19+
if(i+1 >= strs.length){
20+
res.append(palabra.charAt(j));
21+
i = 0;
22+
j++;
23+
}
24+
25+
}
26+
27+
return res.toString();
28+
29+
}
30+
31+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package me.darksnakex.problems;
2+
3+
public class p58 {
4+
5+
public int lengthOfLastWord(String s) {
6+
7+
int cont = 0;
8+
for(int i = s.length()-1; i >= 0 ;i--){
9+
char car = s.charAt(i);
10+
if(car <= 122 && car >= 65){
11+
cont++;
12+
}else if(cont != 0){
13+
return cont;
14+
}
15+
16+
}
17+
return 0;
18+
19+
20+
}
21+
22+
}

0 commit comments

Comments
 (0)