File tree 3 files changed +58
-0
lines changed
3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public int maximum69Number (int num ) {
3
+ char [] chars = String .valueOf (num ).toCharArray ();
4
+ for (int i = 0 ; i < chars .length ; i ++) {
5
+ if (chars [i ] == '6' ) {
6
+ chars [i ] = '9' ;
7
+ break ;
8
+ }
9
+ }
10
+ return Integer .parseInt (String .valueOf (chars ));
11
+ }
12
+ }
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public int [] arrayRankTransform (int [] arr ) {
3
+ PriorityQueue <Integer > pq = new PriorityQueue <>();
4
+ Map <Integer , Integer > map = new HashMap <>();
5
+ int rank = 1 ;
6
+ for (int num : arr ) {
7
+ pq .add (num );
8
+ }
9
+ while (!pq .isEmpty ()) {
10
+ int num = pq .poll ();
11
+ if (!map .containsKey (num )) {
12
+ map .put (num , rank );
13
+ rank ++;
14
+ }
15
+ }
16
+ int [] rankArr = new int [arr .length ];
17
+ for (int i = 0 ; i < arr .length ; i ++) {
18
+ rankArr [i ] = map .get (arr [i ]);
19
+ }
20
+ return rankArr ;
21
+ }
22
+ }
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public String breakPalindrome (String palindrome ) {
3
+ // If empty or of length 1 => return empty
4
+ if (palindrome .length () <= 1 ) {
5
+ return "" ;
6
+ }
7
+ char [] chars = palindrome .toCharArray ();
8
+ for (int i = 0 ; i < chars .length ; i ++) {
9
+ if (chars [i ] != 'a' ) {
10
+ // Skip if the string is of odd length and it is the middle index
11
+ if (palindrome .length () % 2 != 0 && i == palindrome .length () / 2 ) {
12
+ continue ;
13
+ }
14
+ chars [i ] = 'a' ;
15
+ break ;
16
+ }
17
+ // If all chars all 'a' update last char to 'b'
18
+ if (i == chars .length - 1 ) {
19
+ chars [i ] = 'b' ;
20
+ }
21
+ }
22
+ return String .valueOf (chars );
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments