File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed
src/main/java/me/darksnakex/problems Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments