File tree Expand file tree Collapse file tree 4 files changed +39
-65
lines changed
g0601_0700/s0620_not_boring_movies
g1001_1100/s1012_numbers_with_repeated_digits
s1309_decrypt_string_from_alphabet_to_integer_mapping
s1392_longest_happy_prefix Expand file tree Collapse file tree 4 files changed +39
-65
lines changed Original file line number Diff line number Diff line change 11# Write your MySQL query statement below
2- # #Easy #Database #2022_03_21_Time_258_ms_(28.33%)_Space_0B_(100.00%)
3- SELECT *
4- FROM cinema
5- WHERE description != ' boring'
6- AND ID % 2 = 1
7- ORDER BY rating desc ;
2+ # #Easy #Database #2025_04_23_Time_259_ms_(64.69%)_Space_0.0_MB_(100.00%)
3+ SELECT id, movie, description, rating
4+ FROM Cinema
5+ WHERE description != ' boring' AND id % 2 != 0
6+ ORDER BY rating DESC ;
Original file line number Diff line number Diff line change 11package g1001_1100 .s1012_numbers_with_repeated_digits ;
22
3- // #Hard #Dynamic_Programming #Math #2022_02_25_Time_3_ms_(28.17%)_Space_41.8_MB_(7.04 %)
3+ // #Hard #Dynamic_Programming #Math #2025_04_23_Time_2_ms_(50.64%)_Space_40.70_MB_(60.90 %)
44
55import java .util .HashSet ;
66
Original file line number Diff line number Diff line change 11package g1301_1400 .s1309_decrypt_string_from_alphabet_to_integer_mapping ;
22
33// #Easy #String #Programming_Skills_I_Day_9_String
4- // #2022_03_15_Time_6_ms_(28.25%)_Space_42.6_MB_(29.40%)
5-
6- import java .util .HashMap ;
7- import java .util .Map ;
4+ // #2025_04_23_Time_0_ms_(100.00%)_Space_41.42_MB_(89.95%)
85
96public class Solution {
107 public String freqAlphabets (String s ) {
11- Map <String , String > map = new HashMap <>();
12- map .put ("1" , "a" );
13- map .put ("2" , "b" );
14- map .put ("3" , "c" );
15- map .put ("4" , "d" );
16- map .put ("5" , "e" );
17- map .put ("6" , "f" );
18- map .put ("7" , "g" );
19- map .put ("8" , "h" );
20- map .put ("9" , "i" );
21- map .put ("10#" , "j" );
22- map .put ("11#" , "k" );
23- map .put ("12#" , "l" );
24- map .put ("13#" , "m" );
25- map .put ("14#" , "n" );
26- map .put ("15#" , "o" );
27- map .put ("16#" , "p" );
28- map .put ("17#" , "q" );
29- map .put ("18#" , "r" );
30- map .put ("19#" , "s" );
31- map .put ("20#" , "t" );
32- map .put ("21#" , "u" );
33- map .put ("22#" , "v" );
34- map .put ("23#" , "w" );
35- map .put ("24#" , "x" );
36- map .put ("25#" , "y" );
37- map .put ("26#" , "z" );
38- StringBuilder sb = new StringBuilder ();
39- int i = 0 ;
40- while (i < s .length ()) {
41- if ((Integer .parseInt ("" + s .charAt (i )) == 1 || Integer .parseInt ("" + s .charAt (i )) == 2 )
42- && i + 1 < s .length ()
43- && i + 2 < s .length ()
44- && s .charAt (i + 2 ) == '#' ) {
45- sb .append (map .get (s .substring (i , i + 3 )));
46- i += 3 ;
8+ StringBuilder builder = new StringBuilder ();
9+ int i = s .length () - 1 ;
10+ while (i >= 0 ) {
11+ if (s .charAt (i ) == '#' ) {
12+ decryptor (builder , i - 1 , i - 2 , s );
13+ i -= 3 ;
4714 } else {
48- sb .append (map .get ("" + s .charAt (i )));
49- i ++;
15+ char ch = (char ) (s .charAt (i ) - '0' + 96 );
16+ builder .append (ch );
17+ i --;
5018 }
5119 }
52- return sb .toString ();
20+ return builder .reverse ().toString ();
21+ }
22+
23+ private void decryptor (StringBuilder builder , int a , int b , String s ) {
24+ builder .append ((char ) (((s .charAt (b ) - '0' ) * 10 + s .charAt (a ) - '0' ) + 96 ));
5325 }
5426}
Original file line number Diff line number Diff line change 11package g1301_1400 .s1392_longest_happy_prefix ;
22
33// #Hard #String #Hash_Function #String_Matching #Rolling_Hash
4- // #2022_03_17_Time_39_ms_(28.37%)_Space_42.6_MB_(94.23 %)
4+ // #2025_04_23_Time_5_ms_(100.00%)_Space_45.92_MB_(23.63 %)
55
66public class Solution {
77 public String longestPrefix (String s ) {
8- int times = 2 ;
9- long prefixHash = 0 ;
10- long suffixHash = 0 ;
11- long multiplier = 1 ;
12- long len = 0 ;
13- // use some large prime as a modulo to avoid overflow errors, e.g. 10 ^ 9 + 7.
14- long mod = 1000000007 ;
15- for (int i = 0 ; i < s .length () - 1 ; i ++) {
16- prefixHash = (prefixHash * times + s .charAt (i )) % mod ;
17- suffixHash = (multiplier * s .charAt (s .length () - i - 1 ) + suffixHash ) % mod ;
18- if (prefixHash == suffixHash ) {
19- len = (long ) i + 1 ;
8+ char c [] = s .toCharArray ();
9+ int n = c .length ;
10+ int a [] = new int [n ];
11+ int max = 0 , i = 1 ;
12+ while (i < n ) {
13+ if (c [max ] == c [i ]) {
14+ max ++;
15+ a [i ] = max ;
16+ i ++;
17+ } else {
18+ if (max > 0 ) {
19+ max = a [max - 1 ];
20+ } else {
21+ a [i ] = 0 ;
22+ i ++;
23+ }
2024 }
21- multiplier = multiplier * times % mod ;
2225 }
23- return s .substring (0 , ( int ) len );
26+ return s .substring (0 , a [ n - 1 ] );
2427 }
2528}
You can’t perform that action at this time.
0 commit comments