File tree Expand file tree Collapse file tree 9 files changed +236
-0
lines changed
src/main/java/me/darksnakex/problems/java Expand file tree Collapse file tree 9 files changed +236
-0
lines changed Original file line number Diff line number Diff line change 1+ package me .darksnakex .problems .java ;
2+
3+
4+ public class p1323 {
5+
6+ public int maximum69Number (int num ) {
7+
8+ char [] arr = Integer .toString (num ).toCharArray ();
9+
10+ for (int i = 0 ; i < arr .length ; i ++){
11+ if (arr [i ] == '6' ){
12+ arr [i ] = '9' ;
13+ break ;
14+ }
15+ }
16+
17+ int res = 0 ;
18+ int pow = 0 ;
19+ for (int i = arr .length -1 ; i >= 0 ; i --){
20+ res += (int )(Math .pow (10 ,pow ))*(arr [i ]-48 );
21+ pow ++;
22+ }
23+
24+ return res ;
25+ }
26+
27+ }
Original file line number Diff line number Diff line change 1+ package me .darksnakex .problems .java ;
2+
3+ public class p171 {
4+
5+ public int titleToNumber (String columnTitle ) {
6+
7+ int res = 0 ;
8+ int temp = 0 ;
9+ for (int i = columnTitle .length ()-1 ; i >=0 ; i --){
10+ int numac = columnTitle .charAt (temp )-64 ;
11+ res += (int ) (numac *Math .pow (26 ,i ));
12+ temp ++;
13+
14+ }
15+
16+ return res ;
17+ }
18+
19+ }
Original file line number Diff line number Diff line change 1+ package me .darksnakex .problems .java ;
2+
3+ public class p2264 {
4+
5+ public String largestGoodInteger (String num ) {
6+
7+ String res = "" ;
8+ char anterior = 0 ;
9+ char anterior2 = 0 ;
10+ for (int i = 0 ; i < num .length (); i ++){
11+ if (anterior == anterior2 && anterior2 == num .charAt (i )) {
12+ if (res .isEmpty () || num .charAt (i ) > res .charAt (0 )) {
13+ res = anterior2 + String .valueOf (anterior ) + num .charAt (i );
14+ anterior = 0 ;
15+ }
16+ }
17+ anterior2 = anterior ;
18+ anterior = num .charAt (i );
19+ }
20+
21+
22+ return res ;
23+
24+ }
25+
26+ }
Original file line number Diff line number Diff line change 1+ package me .darksnakex .problems .java ;
2+
3+ import java .util .Arrays ;
4+
5+ public class p2574 {
6+
7+ public int [] leftRightDifference (int [] nums ) {
8+
9+ int [] leftsum = new int [nums .length ];
10+ int [] rightsum = new int [nums .length ];
11+ int [] res = new int [nums .length ];
12+
13+
14+ int acumulado = 0 ;
15+ int j = 1 ;
16+ for (int i = 0 ; i < nums .length ; i ++){
17+
18+ if (i != 0 ) {
19+ leftsum [j ] = acumulado ;
20+ j ++;
21+ }
22+ acumulado += nums [i ];
23+ }
24+
25+ System .out .println (Arrays .toString (leftsum ));
26+
27+ acumulado = 0 ;
28+ j = nums .length -2 ;
29+ for (int i = nums .length -1 ; i >= 0 ; i --){
30+ if (i != nums .length -1 ) {
31+ rightsum [j ] = acumulado ;
32+ j --;
33+ }
34+ acumulado += nums [i ];
35+ }
36+
37+ System .out .println (Arrays .toString (rightsum ));
38+
39+ for (int i = 0 ; i < nums .length ; i ++){
40+ res [i ] = Math .abs (leftsum [i ]-rightsum [i ]);
41+ }
42+
43+
44+
45+ return res ;
46+
47+ }
48+
49+ }
Original file line number Diff line number Diff line change 1+ package me .darksnakex .problems .java ;
2+
3+
4+
5+ public class p2798 {
6+
7+
8+ public int numberOfEmployeesWhoMetTarget (int [] hours , int target ) {
9+
10+ int res = 0 ;
11+ for (int hour : hours ) {
12+ if (hour >= target ) {
13+ res ++;
14+ }
15+ }
16+ return res ;
17+
18+ }
19+
20+
21+ }
Original file line number Diff line number Diff line change 1+ package me .darksnakex .problems .java ;
2+
3+ public class p326 {
4+
5+ public boolean isPowerOfThree (int n ) {
6+
7+ if (n == 0 ){
8+ return false ;
9+ }
10+
11+ double res ;
12+ int res2 ;
13+
14+ res = (double ) n /3 ;
15+ res2 = n /3 ;
16+
17+ return res == res2 ;
18+
19+ }
20+
21+ }
Original file line number Diff line number Diff line change 1+ package me .darksnakex .problems .java ;
2+
3+ public class p338 {
4+
5+ public int [] countBits (int n ) {
6+ int [] res = new int [n +1 ];
7+
8+ for (int i = n ; i >0 ; i --){
9+ res [i ]=Integer .bitCount (n );
10+ n --;
11+ }
12+
13+
14+ return res ;
15+ }
16+
17+ }
Original file line number Diff line number Diff line change 1+ package me .darksnakex .problems .java ;
2+
3+ import java .util .HashSet ;
4+ import java .util .Set ;
5+
6+ public class p357 {
7+
8+ public int countNumbersWithUniqueDigits (int n ) {
9+
10+ int res = 0 ;
11+ int max = (int ) Math .pow (10 ,n );
12+
13+ for (int i = 0 ; i < max ; i ++){
14+ if (!estaRepetido (Integer .toString (i ))){
15+ res ++;
16+ }
17+ }
18+
19+ return res ;
20+
21+ }
22+
23+ private boolean estaRepetido (String string ) {
24+ if (string .length () <= 1 ) {
25+ return false ;
26+ }
27+ Set <Character > set = new HashSet <>();
28+ for (char car : string .toCharArray ()) {
29+
30+ if (!set .add (car )) {
31+ return true ;
32+ }
33+ }
34+
35+ return false ;
36+ }
37+
38+ }
Original file line number Diff line number Diff line change 1+ package me .darksnakex .problems .java ;
2+
3+
4+ public class p9 {
5+
6+ public boolean isPalindrome (int x ) {
7+ String res = Integer .toString (x );
8+ int j = res .length ()-1 ;
9+ for (int i = 0 ; i < res .length ()/2 ; i ++){
10+ if (res .charAt (j ) != res .charAt (i )){
11+ return false ;
12+ }
13+ j --;
14+ }
15+ return true ;
16+ }
17+
18+ }
You can’t perform that action at this time.
0 commit comments