├── settings.gradle ├── .gitignore ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── src ├── main │ └── java │ │ ├── g0101_0200 │ │ ├── s0195_tenth_line │ │ │ └── script.sh │ │ ├── s0193_valid_phone_numbers │ │ │ └── script.sh │ │ ├── s0192_word_frequency │ │ │ └── script.sh │ │ ├── s0178_rank_scores │ │ │ └── script.sql │ │ ├── s0182_duplicate_emails │ │ │ └── script.sql │ │ ├── s0196_delete_duplicate_emails │ │ │ └── script.sql │ │ ├── s0175_combine_two_tables │ │ │ └── script.sql │ │ ├── s0183_customers_who_never_order │ │ │ └── script.sql │ │ ├── s0197_rising_temperature │ │ │ └── script.sql │ │ ├── s0181_employees_earning_more_than_their_managers │ │ │ └── script.sql │ │ ├── s0177_nth_highest_salary │ │ │ └── script.sql │ │ ├── s0180_consecutive_numbers │ │ │ └── script.sql │ │ ├── s0176_second_highest_salary │ │ │ └── script.sql │ │ ├── s0194_transpose_file │ │ │ ├── readme.md │ │ │ └── script.sh │ │ ├── s0171_excel_sheet_column_number │ │ │ └── Solution.java │ │ ├── s0185_department_top_three_salaries │ │ │ └── script.sql │ │ ├── s0172_factorial_trailing_zeroes │ │ │ └── Solution.java │ │ └── s0137_single_number_ii │ │ │ └── Solution.java │ │ ├── g1001_1100 │ │ ├── s1095_find_in_mountain_array │ │ │ └── MountainArray.java │ │ ├── s1068_product_sales_analysis_i │ │ │ └── script.sql │ │ ├── s1045_customers_who_bought_all_products │ │ │ └── script.sql │ │ ├── s1075_project_employees_i │ │ │ └── script.sql │ │ ├── s1025_divisor_game │ │ │ └── Solution.java │ │ ├── s1050_actors_and_directors_who_cooperated_at_least_three_times │ │ │ └── script.sql │ │ ├── s1070_product_sales_analysis_iii │ │ │ └── script.sql │ │ ├── s1037_valid_boomerang │ │ │ └── Solution.java │ │ └── s1016_binary_string_with_substrings_representing_1_to_n │ │ │ └── Solution.java │ │ ├── g1601_1700 │ │ ├── s1683_invalid_tweets │ │ │ └── script.sql │ │ ├── s1667_fix_names_in_a_table │ │ │ └── script.sql │ │ ├── s1693_daily_leads_and_partners │ │ │ └── script.sql │ │ ├── s1633_percentage_of_users_attended_a_contest │ │ │ └── script.sql │ │ ├── s1661_average_time_of_process_per_machine │ │ │ └── script.sql │ │ └── s1668_maximum_repeating_substring │ │ │ └── Solution.java │ │ ├── g2801_2900 │ │ ├── s2879_display_the_first_three_rows │ │ │ └── solution.py │ │ ├── s2880_select_data │ │ │ └── solution.py │ │ ├── s2878_get_the_size_of_a_dataframe │ │ │ └── solution.py │ │ ├── s2884_modify_columns │ │ │ └── solution.py │ │ ├── s2886_change_data_type │ │ │ └── solution.py │ │ ├── s2887_fill_missing_data │ │ │ └── solution.py │ │ ├── s2888_reshape_data_concatenate │ │ │ └── solution.py │ │ ├── s2889_reshape_data_pivot │ │ │ └── solution.py │ │ ├── s2890_reshape_data_melt │ │ │ └── solution.py │ │ ├── s2881_create_a_new_column │ │ │ └── solution.py │ │ ├── s2883_drop_missing_data │ │ │ └── solution.py │ │ ├── s2882_drop_duplicate_rows │ │ │ └── solution.py │ │ ├── s2877_create_a_dataframe_from_list │ │ │ └── solution.py │ │ ├── s2885_rename_columns │ │ │ └── solution.py │ │ └── s2806_account_balance_after_rounded_purchase │ │ │ └── Solution.java │ │ ├── g0501_0600 │ │ ├── s0596_classes_more_than_5_students │ │ │ └── script.sql │ │ ├── s0584_find_customer_referee │ │ │ └── script.sql │ │ ├── s0595_big_countries │ │ │ └── script.sql │ │ ├── s0577_employee_bonus │ │ │ └── script.sql │ │ ├── s0504_base_7 │ │ │ ├── Solution.java │ │ │ └── readme.md │ │ ├── s0511_game_play_analysis_i │ │ │ └── script.sql │ │ ├── s0570_managers_with_at_least_5_direct_reports │ │ │ └── script.sql │ │ ├── s0586_customer_placing_the_largest_number_of_orders │ │ │ └── script.sql │ │ ├── s0585_investments_in_2016 │ │ │ └── script.sql │ │ ├── s0550_game_play_analysis_iv │ │ │ └── script.sql │ │ ├── s0507_perfect_number │ │ │ └── Solution.java │ │ ├── s0575_distribute_candies │ │ │ └── Solution.java │ │ └── s0561_array_partition_i │ │ │ └── Solution.java │ │ ├── g2701_2800 │ │ ├── s2727_is_object_empty │ │ │ └── solution.ts │ │ ├── s2769_find_the_maximum_achievable_number │ │ │ └── Solution.java │ │ ├── s2703_return_length_of_arguments_passed │ │ │ └── solution.ts │ │ ├── s2724_sort_by │ │ │ └── solution.ts │ │ ├── s2723_add_two_promises │ │ │ └── solution.ts │ │ ├── s2739_total_distance_traveled │ │ │ └── Solution.java │ │ ├── s2710_remove_trailing_zeros_from_a_string │ │ │ └── Solution.java │ │ ├── s2798_number_of_employees_who_met_the_target │ │ │ └── Solution.java │ │ ├── s2778_sum_of_squares_of_special_elements │ │ │ └── Solution.java │ │ └── s2745_construct_the_longest_new_string │ │ │ └── Solution.java │ │ ├── g1501_1600 │ │ ├── s1517_find_users_with_valid_e_mails │ │ │ └── script.sql │ │ ├── s1587_bank_account_summary_ii │ │ │ └── script.sql │ │ ├── s1551_minimum_operations_to_make_array_equal │ │ │ └── Solution.java │ │ ├── s1527_patients_with_a_condition │ │ │ └── script.sql │ │ ├── s1581_customer_who_visited_but_did_not_make_any_transactions │ │ │ └── script.sql │ │ ├── s1556_thousand_separator │ │ │ └── readme.md │ │ ├── s1523_count_odd_numbers_in_an_interval_range │ │ │ └── Solution.java │ │ ├── s1550_three_consecutive_odds │ │ │ └── Solution.java │ │ ├── s1529_bulb_switcher_iv │ │ │ └── Solution.java │ │ └── s1588_sum_of_all_odd_length_subarrays │ │ │ └── Solution.java │ │ ├── g0601_0700 │ │ ├── s0627_swap_salary │ │ │ └── script.sql │ │ ├── s0610_triangle_judgement │ │ │ └── script.sql │ │ ├── s0620_not_boring_movies │ │ │ └── script.sql │ │ ├── s0619_biggest_single_number │ │ │ └── script.sql │ │ ├── s0607_sales_person │ │ │ └── script.sql │ │ ├── s0608_tree_node │ │ │ └── script.sql │ │ ├── s0626_exchange_seats │ │ │ └── script.sql │ │ ├── s0602_friend_requests_ii_who_has_the_most_friends │ │ │ └── script.sql │ │ ├── s0657_robot_return_to_origin │ │ │ └── Solution.java │ │ └── s0633_sum_of_square_numbers │ │ │ └── readme.md │ │ ├── g1701_1800 │ │ ├── s1757_recyclable_and_low_fat_products │ │ │ └── script.sql │ │ ├── s1729_find_followers_count │ │ │ └── script.sql │ │ ├── s1741_find_total_time_spent_by_each_employee │ │ │ └── script.sql │ │ ├── s1791_find_center_of_star_graph │ │ │ └── Solution.java │ │ ├── s1731_the_number_of_employees_which_report_to_each_employee │ │ │ └── script.sql │ │ ├── s1789_primary_department_for_each_employee │ │ │ └── script.sql │ │ ├── s1720_decode_xored_array │ │ │ └── Solution.java │ │ ├── s1795_rearrange_products_table │ │ │ └── script.sql │ │ └── s1780_check_if_number_is_a_sum_of_powers_of_three │ │ │ └── Solution.java │ │ ├── g1301_1400 │ │ ├── s1378_replace_employee_id_with_the_unique_identifier │ │ │ └── script.sql │ │ ├── s1393_capital_gainloss │ │ │ └── script.sql │ │ ├── s1321_restaurant_growth │ │ │ └── script.sql │ │ ├── s1327_list_the_products_ordered_in_a_period │ │ │ └── script.sql │ │ ├── s1332_remove_palindromic_subsequences │ │ │ └── Solution.java │ │ └── s1341_movie_rating │ │ │ └── script.sql │ │ ├── g3401_3500 │ │ ├── s3436_find_valid_emails │ │ │ └── script.sql │ │ ├── s3465_find_products_with_valid_serial_numbers │ │ │ └── script.sql │ │ ├── s3492_maximum_containers_on_a_ship │ │ │ └── Solution.java │ │ ├── s3498_reverse_degree_of_a_string │ │ │ └── Solution.java │ │ └── s3427_sum_of_variable_length_subarrays │ │ │ └── Solution.java │ │ ├── g2301_2400 │ │ ├── s2356_number_of_unique_subjects_taught_by_each_teacher │ │ │ └── script.sql │ │ ├── s2317_maximum_xor_after_operations │ │ │ └── Solution.java │ │ ├── s2358_maximum_number_of_groups_entering_a_competition │ │ │ └── Solution.java │ │ ├── s2335_minimum_amount_of_time_to_fill_cups │ │ │ └── Solution.java │ │ └── s2348_number_of_zero_filled_subarrays │ │ │ └── Solution.java │ │ ├── g1101_1200 │ │ ├── s1148_article_views_i │ │ │ └── script.sql │ │ ├── s1108_defanging_an_ip_address │ │ │ ├── Solution.java │ │ │ └── readme.md │ │ ├── s1141_user_activity_for_the_past_30_days_i │ │ │ └── script.sql │ │ ├── s1174_immediate_food_delivery_ii │ │ │ └── script.sql │ │ ├── s1164_product_price_at_a_given_date │ │ │ └── script.sql │ │ └── s1193_monthly_transactions_i │ │ │ └── script.sql │ │ ├── g2201_2300 │ │ ├── s2235_add_two_integers │ │ │ └── Solution.java │ │ ├── s2236_root_equals_sum_of_children │ │ │ └── Solution.java │ │ ├── s2255_count_prefixes_of_a_given_string │ │ │ └── Solution.java │ │ └── s2278_percentage_of_letter_in_string │ │ │ └── Solution.java │ │ ├── g1801_1900 │ │ ├── s1890_the_latest_login_in_2020 │ │ │ └── script.sql │ │ ├── s1873_calculate_special_bonus │ │ │ └── script.sql │ │ ├── s1837_sum_of_digits_in_base_k │ │ │ └── Solution.java │ │ ├── s1816_truncate_sentence │ │ │ └── Solution.java │ │ ├── s1835_find_xor_sum_of_all_pairs_bitwise_and │ │ │ └── Solution.java │ │ └── s1832_check_if_the_sentence_is_pangram │ │ │ └── Solution.java │ │ ├── g0201_0300 │ │ ├── s0292_nim_game │ │ │ └── Solution.java │ │ ├── s0258_add_digits │ │ │ └── Solution.java │ │ ├── s0233_number_of_digit_one │ │ │ └── readme.md │ │ ├── s0268_missing_number │ │ │ └── Solution.java │ │ └── s0204_count_primes │ │ │ └── readme.md │ │ ├── g2601_2700 │ │ ├── s2667_create_hello_world_function │ │ │ └── solution.ts │ │ ├── s2621_sleep │ │ │ └── solution.ts │ │ ├── s2635_apply_transform_over_each_element_in_array │ │ │ └── solution.ts │ │ ├── s2666_allow_one_function_call │ │ │ └── solution.ts │ │ ├── s2651_calculate_delayed_arrival_time │ │ │ └── Solution.java │ │ ├── s2634_filter_elements_from_array │ │ │ └── solution.ts │ │ ├── s2620_counter │ │ │ └── solution.ts │ │ ├── s2626_array_reduce_transformation │ │ │ └── solution.ts │ │ ├── s2619_array_prototype_last │ │ │ └── solution.ts │ │ ├── s2683_neighboring_bitwise_xor │ │ │ └── Solution.java │ │ ├── s2677_chunk_array │ │ │ └── solution.ts │ │ ├── s2629_function_composition │ │ │ └── solution.ts │ │ └── s2618_check_if_object_instance_of_class │ │ │ └── solution.ts │ │ ├── g1901_2000 │ │ ├── s1978_employees_whose_manager_left_the_company │ │ │ └── script.sql │ │ ├── s1965_employees_with_missing_information │ │ │ └── script.sql │ │ ├── s1952_three_divisors │ │ │ └── Solution.java │ │ ├── s1920_build_array_from_permutation │ │ │ └── Solution.java │ │ ├── s1907_count_salary_categories │ │ │ └── script.sql │ │ ├── s1913_maximum_product_difference_between_two_pairs │ │ │ └── Solution.java │ │ ├── s1967_number_of_strings_that_appear_as_substrings_in_word │ │ │ └── Solution.java │ │ └── s1955_count_number_of_special_subsequences │ │ │ └── Solution.java │ │ ├── g1201_1300 │ │ ├── s1211_queries_quality_and_percentage │ │ │ └── script.sql │ │ ├── s1204_last_person_to_fit_in_the_bus │ │ │ └── script.sql │ │ ├── s1251_average_selling_price │ │ │ └── script.sql │ │ ├── s1280_students_and_examinations │ │ │ └── script.sql │ │ ├── s1227_airplane_seat_assignment_probability │ │ │ └── Solution.java │ │ ├── s1299_replace_elements_with_greatest_element_on_right_side │ │ │ └── Solution.java │ │ └── s1287_element_appearing_more_than_25_in_sorted_array │ │ │ └── Solution.java │ │ ├── g2401_2500 │ │ ├── s2413_smallest_even_multiple │ │ │ └── Solution.java │ │ ├── s2481_minimum_cuts_to_divide_a_circle │ │ │ └── Solution.java │ │ ├── s2427_number_of_common_factors │ │ │ └── Solution.java │ │ ├── s2469_convert_the_temperature │ │ │ └── Solution.java │ │ └── s2433_find_the_original_array_of_prefix_xor │ │ │ └── Solution.java │ │ ├── g0301_0400 │ │ ├── s0390_elimination_game │ │ │ └── Solution.java │ │ ├── s0319_bulb_switcher │ │ │ └── Solution.java │ │ ├── s0371_sum_of_two_integers │ │ │ └── readme.md │ │ ├── s0342_power_of_four │ │ │ └── Solution.java │ │ ├── s0367_valid_perfect_square │ │ │ └── readme.md │ │ ├── s0344_reverse_string │ │ │ └── Solution.java │ │ ├── s0386_lexicographical_numbers │ │ │ └── readme.md │ │ ├── s0326_power_of_three │ │ │ └── Solution.java │ │ └── s0357_count_numbers_with_unique_digits │ │ │ └── readme.md │ │ ├── g0401_0500 │ │ ├── s0476_number_complement │ │ │ └── Solution.java │ │ ├── s0461_hamming_distance │ │ │ └── Solution.java │ │ ├── s0430_flatten_a_multilevel_doubly_linked_list │ │ │ └── Node.java │ │ └── s0479_largest_palindrome_product │ │ │ └── readme.md │ │ ├── g3601_3700 │ │ ├── s3658_gcd_of_odd_and_even_sums │ │ │ └── Solution.java │ │ ├── s3648_minimum_sensors_to_cover_grid │ │ │ └── Solution.java │ │ ├── s3674_minimum_operations_to_equalize_array │ │ │ └── Solution.java │ │ ├── s3683_earliest_time_to_finish_one_task │ │ │ └── Solution.java │ │ ├── s3688_bitwise_or_of_even_numbers_in_an_array │ │ │ └── Solution.java │ │ └── s3657_find_loyal_customers │ │ │ └── script.sql │ │ ├── g1401_1500 │ │ ├── s1407_top_travellers │ │ │ └── script.sql │ │ ├── s1484_group_sold_products_by_the_date │ │ │ └── script.sql │ │ ├── s1480_running_sum_of_1d_array │ │ │ └── Solution.java │ │ ├── s1470_shuffle_the_array │ │ │ └── Solution.java │ │ ├── s1413_minimum_value_to_get_positive_step_by_step_sum │ │ │ └── Solution.java │ │ └── s1486_xor_operation_in_an_array │ │ │ └── Solution.java │ │ ├── g3301_3400 │ │ ├── s3374_first_letter_capitalization_ii │ │ │ └── solution.py │ │ ├── s3370_smallest_number_with_all_set_bits │ │ │ └── Solution.java │ │ └── s3340_check_balanced_string │ │ │ └── Solution.java │ │ ├── g2501_2600 │ │ ├── s2579_count_total_number_of_colored_cells │ │ │ └── Solution.java │ │ ├── s2549_count_distinct_numbers_on_board │ │ │ └── Solution.java │ │ ├── s2546_apply_bitwise_operations_to_make_strings_equal │ │ │ └── Solution.java │ │ ├── s2527_find_xor_beauty_of_array │ │ │ └── Solution.java │ │ ├── s2545_sort_the_students_by_their_kth_score │ │ │ └── Solution.java │ │ ├── s2582_pass_the_pillow │ │ │ └── Solution.java │ │ ├── s2544_alternating_digit_sum │ │ │ └── Solution.java │ │ └── s2520_count_the_digits_that_divide_a_number │ │ │ └── Solution.java │ │ ├── g0801_0900 │ │ ├── s0836_rectangle_overlap │ │ │ └── Solution.java │ │ ├── s0810_chalkboard_xor_game │ │ │ └── Solution.java │ │ ├── s0852_peak_index_in_a_mountain_array │ │ │ └── Solution.java │ │ ├── s0869_reordered_power_of_2 │ │ │ └── readme.md │ │ └── s0858_mirror_reflection │ │ │ └── Solution.java │ │ ├── g3201_3300 │ │ ├── s3220_odd_and_even_transactions │ │ │ └── script.sql │ │ ├── s3210_find_the_encrypted_string │ │ │ └── Solution.java │ │ ├── s3222_find_the_winning_player_in_coin_game │ │ │ └── Solution.java │ │ ├── s3274_check_if_two_chessboard_squares_have_the_same_color │ │ │ └── Solution.java │ │ └── s3282_reach_end_of_array_with_max_score │ │ │ └── Solution.java │ │ ├── g2101_2200 │ │ ├── s2119_a_number_after_a_double_reversal │ │ │ └── Solution.java │ │ ├── s2177_find_three_consecutive_integers_that_sum_to_a_given_number │ │ │ └── Solution.java │ │ └── s2185_counting_words_with_a_given_prefix │ │ │ └── Solution.java │ │ ├── g3001_3100 │ │ ├── s3021_alice_and_bob_playing_flower_game │ │ │ └── Solution.java │ │ ├── s3091_apply_operations_to_make_sum_of_array_greater_than_or_equal_to_k │ │ │ └── Solution.java │ │ ├── s3046_split_the_array │ │ │ └── Solution.java │ │ ├── s3065_minimum_operations_to_exceed_threshold_value_i │ │ │ └── Solution.java │ │ └── s3028_ant_on_the_boundary │ │ │ └── Solution.java │ │ ├── g3501_3600 │ │ ├── s3513_number_of_unique_xor_triplets_i │ │ │ └── Solution.java │ │ ├── s3512_minimum_operations_to_make_array_sum_divisible_by_k │ │ │ └── Solution.java │ │ ├── s3516_find_closest_person │ │ │ └── Solution.java │ │ └── s3502_minimum_cost_to_reach_every_position │ │ │ └── Solution.java │ │ ├── g3101_3200 │ │ ├── s3178_find_the_child_who_has_the_ball_after_k_seconds │ │ │ └── Solution.java │ │ ├── s3110_score_of_a_string │ │ │ └── Solution.java │ │ ├── s3190_find_minimum_operations_to_make_all_elements_divisible_by_three │ │ │ └── Solution.java │ │ └── s3131_find_the_integer_added_to_array_i │ │ │ └── Solution.java │ │ ├── g0701_0800 │ │ ├── s0717_1_bit_and_2_bit_characters │ │ │ └── Solution.java │ │ ├── s0779_k_th_symbol_in_grammar │ │ │ └── Solution.java │ │ ├── s0709_to_lower_case │ │ │ ├── Solution.java │ │ │ └── readme.md │ │ └── s0767_reorganize_string │ │ │ └── readme.md │ │ ├── g2001_2100 │ │ └── s2057_smallest_index_with_equal_value │ │ │ └── Solution.java │ │ ├── g0001_0100 │ │ ├── s0059_spiral_matrix_ii │ │ │ └── readme.md │ │ ├── s0047_permutations_ii │ │ │ └── readme.md │ │ └── s0067_add_binary │ │ │ └── readme.md │ │ ├── g0901_1000 │ │ └── s0912_sort_an_array │ │ │ └── readme.md │ │ └── g2901_3000 │ │ ├── s2923_find_champion_i │ │ └── Solution.java │ │ └── s2914_minimum_number_of_changes_to_make_binary_string_beautiful │ │ └── Solution.java └── test │ └── java │ ├── g2601_2700 │ ├── s2619_array_prototype_last │ │ └── solution.test.ts │ ├── s2627_debounce │ │ └── solution.test.ts │ ├── s2621_sleep │ │ └── solution.test.ts │ ├── s2648_generate_fibonacci_sequence │ │ └── solution.test.ts │ ├── s2667_create_hello_world_function │ │ └── solution.test.ts │ ├── s2680_maximum_or │ │ └── SolutionTest.java │ └── s2681_power_of_heroes │ │ └── SolutionTest.java │ ├── g2701_2800 │ ├── s2704_to_be_or_not_to_be │ │ └── solution.test.ts │ ├── s2727_is_object_empty │ │ └── solution.test.ts │ ├── s2703_return_length_of_arguments_passed │ │ └── solution.test.ts │ ├── s2726_calculator_with_method_chaining │ │ └── solution.test.ts │ ├── s2719_count_of_integers │ │ └── SolutionTest.java │ └── s2706_buy_two_chocolates │ │ └── SolutionTest.java │ ├── g0001_0100 │ ├── s0069_sqrtx │ │ └── SolutionTest.java │ ├── s0029_divide_two_integers │ │ └── SolutionTest.java │ ├── s0052_n_queens_ii │ │ └── SolutionTest.java │ ├── s0062_unique_paths │ │ └── SolutionTest.java │ ├── s0070_climbing_stairs │ │ └── SolutionTest.java │ ├── s0067_add_binary │ │ └── SolutionTest.java │ ├── s0096_unique_binary_search_trees │ │ └── SolutionTest.java │ ├── s0043_multiply_strings │ │ └── SolutionTest.java │ ├── s0045_jump_game_ii │ │ └── SolutionTest.java │ ├── s0055_jump_game │ │ └── SolutionTest.java │ ├── s0072_edit_distance │ │ └── SolutionTest.java │ └── s0089_gray_code │ │ └── SolutionTest.java │ ├── g1001_1100 │ ├── s1095_find_in_mountain_array │ │ └── MountainArrayImpl.java │ ├── s1006_clumsy_factorial │ │ └── SolutionTest.java │ └── s1025_divisor_game │ │ └── SolutionTest.java │ ├── g0701_0800 │ ├── s0745_prefix_and_suffix_search │ │ └── WordFilterTest.java │ ├── s0754_reach_a_number │ │ └── SolutionTest.java │ ├── s0753_cracking_the_safe │ │ └── SolutionTest.java │ └── s0796_rotate_string │ │ └── SolutionTest.java │ ├── g0801_0900 │ ├── s0818_race_car │ │ └── SolutionTest.java │ ├── s0808_soup_servings │ │ └── SolutionTest.java │ ├── s0854_k_similar_strings │ │ └── SolutionTest.java │ ├── s0899_orderly_queue │ │ └── SolutionTest.java │ ├── s0877_stone_game │ │ └── SolutionTest.java │ └── s0878_nth_magical_number │ │ └── SolutionTest.java │ ├── g0201_0300 │ ├── s0258_add_digits │ │ └── SolutionTest.java │ ├── s0202_happy_number │ │ └── SolutionTest.java │ ├── s0279_perfect_squares │ │ └── SolutionTest.java │ ├── s0264_ugly_number_ii │ │ └── SolutionTest.java │ ├── s0274_h_index │ │ └── SolutionTest.java │ ├── s0233_number_of_digit_one │ │ └── SolutionTest.java │ ├── s0275_h_index_ii │ │ └── SolutionTest.java │ └── s0242_valid_anagram │ │ └── SolutionTest.java │ ├── g2201_2300 │ ├── s2235_add_two_integers │ │ └── SolutionTest.java │ ├── s2262_total_appeal_of_a_string │ │ └── SolutionTest.java │ └── s2293_min_max_game │ │ └── SolutionTest.java │ ├── g0601_0700 │ ├── s0650_2_keys_keyboard │ │ └── SolutionTest.java │ ├── s0670_maximum_swap │ │ └── SolutionTest.java │ ├── s0664_strange_printer │ │ └── SolutionTest.java │ ├── s0677_map_sum_pairs │ │ └── MapSumTest.java │ ├── s0629_k_inverse_pairs_array │ │ └── SolutionTest.java │ ├── s0657_robot_return_to_origin │ │ └── SolutionTest.java │ ├── s0633_sum_of_square_numbers │ │ └── SolutionTest.java │ ├── s0647_palindromic_substrings │ │ └── SolutionTest.java │ └── s0679_24_game │ │ └── SolutionTest.java │ ├── g0101_0200 │ ├── s0135_candy │ │ └── SolutionTest.java │ └── s0164_maximum_gap │ │ └── SolutionTest.java │ ├── g0301_0400 │ ├── s0319_bulb_switcher │ │ └── SolutionTest.java │ ├── s0400_nth_digit │ │ └── SolutionTest.java │ ├── s0371_sum_of_two_integers │ │ └── SolutionTest.java │ ├── s0343_integer_break │ │ └── SolutionTest.java │ ├── s0390_elimination_game │ │ └── SolutionTest.java │ ├── s0312_burst_balloons │ │ └── SolutionTest.java │ ├── s0338_counting_bits │ │ └── SolutionTest.java │ ├── s0367_valid_perfect_square │ │ └── SolutionTest.java │ ├── s0307_range_sum_query_mutable │ │ └── NumArrayTest.java │ └── s0392_is_subsequence │ │ └── SolutionTest.java │ ├── g1901_2000 │ ├── s1952_three_divisors │ │ └── SolutionTest.java │ └── s1925_count_square_sum_triples │ │ └── SolutionTest.java │ ├── g3101_3200 │ ├── s3133_minimum_array_end │ │ └── SolutionTest.java │ ├── s3174_clear_digits │ │ └── SolutionTest.java │ └── s3110_score_of_a_string │ │ └── SolutionTest.java │ ├── g2401_2500 │ ├── s2429_minimize_xor │ │ └── SolutionTest.java │ ├── s2498_frog_jump_ii │ │ └── SolutionTest.java │ └── s2427_number_of_common_factors │ │ └── SolutionTest.java │ ├── com_github_leetcode │ └── EmployeeTest.java │ ├── g0401_0500 │ ├── s0481_magical_string │ │ └── SolutionTest.java │ ├── s0415_add_strings │ │ └── SolutionTest.java │ ├── s0476_number_complement │ │ └── SolutionTest.java │ ├── s0405_convert_a_number_to_hexadecimal │ │ └── SolutionTest.java │ ├── s0461_hamming_distance │ │ └── SolutionTest.java │ └── s0414_third_maximum_number │ │ └── SolutionTest.java │ ├── g0501_0600 │ ├── s0504_base_7 │ │ └── SolutionTest.java │ ├── s0526_beautiful_arrangement │ │ └── SolutionTest.java │ ├── s0541_reverse_string_ii │ │ └── SolutionTest.java │ ├── s0576_out_of_boundary_paths │ │ └── SolutionTest.java │ ├── s0507_perfect_number │ │ └── SolutionTest.java │ ├── s0520_detect_capital │ │ └── SolutionTest.java │ └── s0525_contiguous_array │ │ └── SolutionTest.java │ ├── g1801_1900 │ ├── s1837_sum_of_digits_in_base_k │ │ └── SolutionTest.java │ ├── s1871_jump_game_vii │ │ └── SolutionTest.java │ ├── s1881_maximum_value_after_insertion │ │ └── SolutionTest.java │ └── s1884_egg_drop_with_2_eggs_and_n_floors │ │ └── SolutionTest.java │ ├── g2501_2600 │ ├── s2578_split_with_minimum_sum │ │ └── SolutionTest.java │ ├── s2514_count_anagrams │ │ └── SolutionTest.java │ ├── s2582_pass_the_pillow │ │ └── SolutionTest.java │ └── s2543_check_if_point_is_reachable │ │ └── SolutionTest.java │ ├── g1101_1200 │ └── s1137_n_th_tribonacci_number │ │ └── SolutionTest.java │ ├── g1501_1600 │ ├── s1518_water_bottles │ │ └── SolutionTest.java │ └── s1553_minimum_number_of_days_to_eat_n_oranges │ │ └── SolutionTest.java │ ├── g1401_1500 │ ├── s1496_path_crossing │ │ └── SolutionTest.java │ ├── s1446_consecutive_characters │ │ └── SolutionTest.java │ ├── s1486_xor_operation_in_an_array │ │ └── SolutionTest.java │ └── s1411_number_of_ways_to_paint_n_3_grid │ │ └── SolutionTest.java │ ├── g3001_3100 │ └── s3100_water_bottles_ii │ │ └── SolutionTest.java │ ├── g3201_3300 │ └── s3271_hash_divided_string │ │ └── SolutionTest.java │ ├── g3301_3400 │ └── s3340_check_balanced_string │ │ └── SolutionTest.java │ ├── g1301_1400 │ ├── s1323_maximum_69_number │ │ └── SolutionTest.java │ ├── s1387_sort_integers_by_the_power_value │ │ └── SolutionTest.java │ └── s1399_count_largest_group │ │ └── SolutionTest.java │ ├── g2801_2900 │ └── s2810_faulty_keyboard │ │ └── SolutionTest.java │ ├── g3601_3700 │ └── s3699_number_of_zigzag_arrays_i │ │ └── SolutionTest.java │ └── g3701_3800 │ └── s3707_equal_score_substrings │ └── SolutionTest.java ├── codecov.yml ├── SECURITY.md └── .github └── dependabot.yml /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'LeetCode-in-Java' 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .idea/ 3 | *.iml 4 | .project 5 | .classpath 6 | bin/ 7 | .settings 8 | build/ 9 | .gradle/ 10 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javadev/LeetCode-in-Java/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | sonar.coverage.jacoco.xmlReportPaths=build/jacoco/test/jacocoTestReport.xml 2 | org.gradle.jvmargs=-Xms512m -Xmx2048m 3 | org.gradle.configuration-cache=true 4 | -------------------------------------------------------------------------------- /src/main/java/g0101_0200/s0195_tenth_line/script.sh: -------------------------------------------------------------------------------- 1 | # Read from the file file.txt and output the tenth line to stdout. 2 | # #Easy #Shell #2022_06_28_Time_26_ms_(99.36%)_Space_3.6_MB_(79.41%) 3 | sed -n 10p file.txt 4 | -------------------------------------------------------------------------------- /src/main/java/g1001_1100/s1095_find_in_mountain_array/MountainArray.java: -------------------------------------------------------------------------------- 1 | package g1001_1100.s1095_find_in_mountain_array; 2 | 3 | public interface MountainArray { 4 | int get(int index); 5 | 6 | int length(); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/g1601_1700/s1683_invalid_tweets/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2023_08_16_Time_1184_ms_(78.28%)_Space_0B_(100.00%) 3 | SELECT tweet_id FROM Tweets 4 | WHERE LENGTH(content) > 15; 5 | -------------------------------------------------------------------------------- /src/main/java/g2801_2900/s2879_display_the_first_three_rows/solution.py: -------------------------------------------------------------------------------- 1 | # #Easy #2023_12_23_Time_406_ms_(96.44%)_Space_60.8_MB_(5.67%) 2 | 3 | import pandas as pd 4 | 5 | def selectFirstRows(zs: pd.DataFrame) -> pd.DataFrame: 6 | return zs.head(3) 7 | -------------------------------------------------------------------------------- /src/main/java/g0501_0600/s0596_classes_more_than_5_students/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2022_08_25_Time_290_ms_(74.62%)_Space_0B_(100.00%) 3 | select class 4 | from Courses 5 | group by class 6 | having count(student) >= 5 7 | -------------------------------------------------------------------------------- /src/main/java/g0501_0600/s0584_find_customer_referee/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #SQL_I_Day_1_Select #2022_08_10_Time_531_ms_(58.63%)_Space_0B_(100.00%) 3 | SELECT name FROM customer where referee_id != 2 or referee_id is null; 4 | -------------------------------------------------------------------------------- /src/main/java/g2701_2800/s2727_is_object_empty/solution.ts: -------------------------------------------------------------------------------- 1 | // #Easy #2023_09_19_Time_52_ms_(79.26%)_Space_44.6_MB_(77.05%) 2 | 3 | function isEmpty(obj: Record | any[]): boolean { 4 | return Object.keys(obj).length === 0 5 | } 6 | 7 | export { isEmpty } 8 | -------------------------------------------------------------------------------- /src/main/java/g1501_1600/s1517_find_users_with_valid_e_mails/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2023_08_16_Time_1356_ms_(75.95%)_Space_0B_(100.00%) 3 | SELECT * 4 | FROM Users 5 | WHERE mail REGEXP '^[a-zA-Z][a-zA-Z0-9_.-]*@leetcode[.]com' 6 | -------------------------------------------------------------------------------- /src/main/java/g2801_2900/s2880_select_data/solution.py: -------------------------------------------------------------------------------- 1 | # #Easy #2023_12_23_Time_428_ms_(94.99%)_Space_60_MB_(83.82%) 2 | 3 | import pandas as pd 4 | 5 | def selectData(students: pd.DataFrame) -> pd.DataFrame: 6 | return students[students.student_id == 101][['name','age']] 7 | -------------------------------------------------------------------------------- /src/main/java/g0601_0700/s0627_swap_salary/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #SQL_I_Day_2_Select_and_Order #2022_03_21_Time_191_ms_(96.89%)_Space_0B_(100.00%) 3 | UPDATE Salary SET sex = CASE WHEN sex = 'm' THEN 'f' ELSE 'm' END WHERE TRUE; 4 | -------------------------------------------------------------------------------- /src/main/java/g2801_2900/s2878_get_the_size_of_a_dataframe/solution.py: -------------------------------------------------------------------------------- 1 | # #Easy #2023_12_22_Time_413_ms_(94.68%)_Space_59.9_MB_(74.79%) 2 | 3 | import pandas as pd 4 | 5 | def getDataframeSize(players: pd.DataFrame) -> List[int]: 6 | return[players.shape[0], players.shape[1]] 7 | -------------------------------------------------------------------------------- /src/main/java/g0601_0700/s0610_triangle_judgement/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2023_06_05_Time_499_ms_(62.77%)_Space_0B_(100.00%) 3 | SELECT *, 4 | CASE WHEN x+y>z AND y+z>x AND z+x>y THEN 'Yes' ELSE 'No' END AS triangle 5 | FROM Triangle 6 | -------------------------------------------------------------------------------- /src/main/java/g1701_1800/s1757_recyclable_and_low_fat_products/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #SQL_I_Day_1_Select #2022_05_03_Time_475_ms_(71.54%)_Space_0B_(100.00%) 3 | select product_id from Products 4 | where low_fats='Y' and recyclable='Y' 5 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: off 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: null 9 | base: auto 10 | patch: 11 | default: 12 | target: auto 13 | threshold: null 14 | base: auto 15 | -------------------------------------------------------------------------------- /src/main/java/g0101_0200/s0193_valid_phone_numbers/script.sh: -------------------------------------------------------------------------------- 1 | # Read from the file file.txt and output all valid phone numbers to stdout. 2 | # #Easy #Shell #2022_06_28_Time_112_ms_(75.54%)_Space_3.1_MB_(53.89%) 3 | egrep '^[0-9]{3}-[0-9]{3}-[0-9]{4}$|^\([0-9]{3}\)\s[0-9]{3}-[0-9]{4}$' file.txt 4 | -------------------------------------------------------------------------------- /src/main/java/g0501_0600/s0595_big_countries/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #SQL_I_Day_1_Select #2022_08_25_Time_262_ms_(84.64%)_Space_0B_(100.00%) 3 | select name, population, area 4 | from world 5 | where area >= 3000000 6 | or population >= 25000000 7 | -------------------------------------------------------------------------------- /src/main/java/g0501_0600/s0577_employee_bonus/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2023_05_18_Time_1473_ms_(95.83%)_Space_0B_(100.00%) 3 | SELECT name, bonus 4 | FROM Employee e 5 | LEFT JOIN Bonus b ON e.empId = b.empId 6 | WHERE bonus < 1000 or b.empId is null; 7 | -------------------------------------------------------------------------------- /src/main/java/g1301_1400/s1378_replace_employee_id_with_the_unique_identifier/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2023_08_16_Time_2498_ms_(63.60%)_Space_0B_(100.00%) 3 | select u.unique_id, e.name 4 | from Employees e 5 | left join EmployeeUNI u 6 | on e.id = u.id; 7 | -------------------------------------------------------------------------------- /src/main/java/g2801_2900/s2884_modify_columns/solution.py: -------------------------------------------------------------------------------- 1 | # #Easy #2023_12_23_Time_401_ms_(96.35%)_Space_60.2_MB_(54.27%) 2 | 3 | import pandas as pd 4 | 5 | def modifySalaryColumn(employees: pd.DataFrame) -> pd.DataFrame: 6 | employees['salary'] = employees['salary'] * 2 7 | return employees 8 | -------------------------------------------------------------------------------- /src/main/java/g2801_2900/s2886_change_data_type/solution.py: -------------------------------------------------------------------------------- 1 | # #Easy #2023_12_23_Time_421_ms_(94.57%)_Space_59.2_MB_(92.43%) 2 | 3 | import pandas as pd 4 | 5 | def changeDatatype(students: pd.DataFrame) -> pd.DataFrame: 6 | students['grade'] = students['grade'].astype(int) 7 | return students 8 | -------------------------------------------------------------------------------- /src/main/java/g2801_2900/s2887_fill_missing_data/solution.py: -------------------------------------------------------------------------------- 1 | # #Easy #2023_12_23_Time_404_ms_(97.11%)_Space_59.7_MB_(74.95%) 2 | 3 | import pandas as pd 4 | 5 | def fillMissingValues(products: pd.DataFrame) -> pd.DataFrame: 6 | products['quantity'].fillna(0, inplace=True) 7 | return products 8 | -------------------------------------------------------------------------------- /src/main/java/g2801_2900/s2888_reshape_data_concatenate/solution.py: -------------------------------------------------------------------------------- 1 | # #Easy #2023_12_23_Time_441_ms_(96.26%)_Space_59_MB_(97.37%) 2 | 3 | import pandas as pd 4 | 5 | def concatenateTables(df1: pd.DataFrame, df2: pd.DataFrame) -> pd.DataFrame: 6 | return pd.concat([df1, df2], ignore_index=True) 7 | -------------------------------------------------------------------------------- /src/main/java/g2801_2900/s2889_reshape_data_pivot/solution.py: -------------------------------------------------------------------------------- 1 | # #Easy #2023_12_25_Time_416_ms_(99.87%)_Space_61.8_MB_(21.28%) 2 | 3 | import pandas as pd 4 | 5 | def pivotTable(weather: pd.DataFrame) -> pd.DataFrame: 6 | return weather.pivot(index='month', columns='city', values='temperature') 7 | -------------------------------------------------------------------------------- /src/main/java/g2801_2900/s2890_reshape_data_melt/solution.py: -------------------------------------------------------------------------------- 1 | # #Easy #2023_12_25_Time_446_ms_(97.89%)_Space_60.5_MB_(68.02%) 2 | 3 | import pandas as pd 4 | 5 | def meltTable(report: pd.DataFrame) -> pd.DataFrame: 6 | return report.melt(id_vars='product', var_name='quarter', value_name='sales') 7 | -------------------------------------------------------------------------------- /src/main/java/g3401_3500/s3436_find_valid_emails/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2025_02_04_Time_451_ms_(70.84%)_Space_0.0_MB_(100.00%) 3 | select user_id, email from users 4 | where email regexp '^[A-Za-z0-9_]+@[A-Za-z][A-Za-z0-9_]*\.com$' 5 | order by user_id 6 | -------------------------------------------------------------------------------- /src/main/java/g0101_0200/s0192_word_frequency/script.sh: -------------------------------------------------------------------------------- 1 | # Read from the file words.txt and output the word frequency list to stdout. 2 | # #Medium #Shell #2022_06_28_Time_143_ms_(54.55%)_Space_3.7_MB_(85.88%) 3 | sed -e 's/ /\n/g' words.txt | sed -e '/^$/d' | sort | uniq -c | sort -r | awk '{print $2" "$1}' 4 | -------------------------------------------------------------------------------- /src/main/java/g2301_2400/s2356_number_of_unique_subjects_taught_by_each_teacher/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2023_08_17_Time_964_ms_(79.65%)_Space_0B_(100.00%) 3 | select teacher_id, count(distinct subject_id) as "cnt" 4 | from Teacher 5 | group by teacher_id 6 | -------------------------------------------------------------------------------- /src/main/java/g2801_2900/s2881_create_a_new_column/solution.py: -------------------------------------------------------------------------------- 1 | # #Easy #2023_12_23_Time_437_ms_(81.98%)_Space_60.3_MB_(37.80%) 2 | 3 | import pandas as pd 4 | 5 | def createBonusColumn(employees: pd.DataFrame) -> pd.DataFrame: 6 | employees["bonus"] = employees["salary"] * 2 7 | return employees 8 | -------------------------------------------------------------------------------- /src/main/java/g0601_0700/s0620_not_boring_movies/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 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; 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /src/main/java/g0101_0200/s0178_rank_scores/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #Database #2022_06_26_Time_290_ms_(66.73%)_Space_0B_(100.00%) 3 | SELECT 4 | Score, 5 | DENSE_RANK() OVER (ORDER BY Score DESC) AS Rank 6 | FROM 7 | Scores 8 | ORDER BY 9 | Rank ASC; 10 | -------------------------------------------------------------------------------- /src/main/java/g0101_0200/s0182_duplicate_emails/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #SQL_I_Day_10_Where #2022_06_27_Time_303_ms_(92.08%)_Space_0B_(100.00%) 3 | SELECT 4 | Email 5 | FROM 6 | Person 7 | GROUP BY 8 | Email 9 | HAVING 10 | COUNT(Email) > 1; 11 | -------------------------------------------------------------------------------- /src/main/java/g0501_0600/s0504_base_7/Solution.java: -------------------------------------------------------------------------------- 1 | package g0501_0600.s0504_base_7; 2 | 3 | // #Easy #Math #2022_07_24_Time_0_ms_(100.00%)_Space_39.4_MB_(98.67%) 4 | 5 | public class Solution { 6 | public String convertToBase7(int num) { 7 | return Integer.toString(num, 7); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/g1001_1100/s1068_product_sales_analysis_i/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2023_06_09_Time_1788_ms_(91.74%)_Space_0B_(100.00%) 3 | select product.product_name, sales.sale_year, sales.price from sales 4 | left join product on product.product_id = sales.product_id 5 | -------------------------------------------------------------------------------- /src/main/java/g1101_1200/s1148_article_views_i/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #LeetCode_Curated_SQL_70 #Database #SQL_I_Day_5_Union 3 | # #2023_06_01_Time_783_ms_(64.09%)_Space_0B_(100.00%) 4 | select distinct author_id as id from Views where author_id = viewer_id order by author_id; 5 | -------------------------------------------------------------------------------- /src/main/java/g1701_1800/s1729_find_followers_count/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #SQL_I_Day_7_Function #2022_04_30_Time_456_ms_(88.39%)_Space_0B_(100.00%) 3 | select user_id, count(follower_id) as followers_count 4 | from followers 5 | group by user_id 6 | order by user_id 7 | -------------------------------------------------------------------------------- /src/main/java/g2201_2300/s2235_add_two_integers/Solution.java: -------------------------------------------------------------------------------- 1 | package g2201_2300.s2235_add_two_integers; 2 | 3 | // #Easy #Math #2022_06_10_Time_1_ms_(48.94%)_Space_41_MB_(49.58%) 4 | 5 | public class Solution { 6 | public int sum(int num1, int num2) { 7 | return num1 + num2; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/g2801_2900/s2883_drop_missing_data/solution.py: -------------------------------------------------------------------------------- 1 | # #Easy #2023_12_23_Time_429_ms_(94.97%)_Space_61.2_MB_(12.30%) 2 | 3 | import pandas as pd 4 | 5 | def dropMissingData(students: pd.DataFrame) -> pd.DataFrame: 6 | r = pd.DataFrame(students) 7 | r.dropna(subset='name', inplace=True) 8 | return r 9 | -------------------------------------------------------------------------------- /src/main/java/g0601_0700/s0619_biggest_single_number/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2023_06_05_Time_779_ms_(66.08%)_Space_0B_(100.00%) 3 | SELECT MAX(num) AS num 4 | FROM (SELECT num, COUNT(num) 5 | FROM MyNumbers 6 | GROUP BY num 7 | HAVING COUNT(num) = 1) t 8 | -------------------------------------------------------------------------------- /src/main/java/g1801_1900/s1890_the_latest_login_in_2020/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #SQL_I_Day_8_Function #2022_05_09_Time_571_ms_(73.59%)_Space_0B_(100.00%) 3 | SELECT user_id, MAX(time_stamp) AS last_stamp 4 | FROM Logins 5 | WHERE YEAR(time_stamp) = '2020' 6 | GROUP BY 1; 7 | -------------------------------------------------------------------------------- /src/main/java/g0101_0200/s0196_delete_duplicate_emails/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #SQL_I_Day_2_Select_and_Order #2022_06_28_Time_903_ms_(48.10%)_Space_0B_(100.00%) 3 | DELETE FROM Person 4 | WHERE Id NOT IN (SELECT id FROM (SELECT Email, MIN(Id) AS id FROM Person GROUP BY Email) t) 5 | -------------------------------------------------------------------------------- /src/main/java/g0201_0300/s0292_nim_game/Solution.java: -------------------------------------------------------------------------------- 1 | package g0201_0300.s0292_nim_game; 2 | 3 | // #Easy #Math #Game_Theory #Brainteaser #2022_07_06_Time_0_ms_(100.00%)_Space_40.6_MB_(71.00%) 4 | 5 | public class Solution { 6 | public boolean canWinNim(int n) { 7 | return n % 4 != 0; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/g2601_2700/s2667_create_hello_world_function/solution.ts: -------------------------------------------------------------------------------- 1 | // #Easy #2023_09_10_Time_45_ms_(94.20%)_Space_43.6_MB_(9.97%) 2 | 3 | const createHelloWorld = () => () => "Hello World"; 4 | 5 | /* 6 | * const f = createHelloWorld(); 7 | * f(); // "Hello World" 8 | */ 9 | 10 | export { createHelloWorld } 11 | -------------------------------------------------------------------------------- /src/main/java/g0501_0600/s0511_game_play_analysis_i/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #LeetCode_Curated_SQL_70 #Database #SQL_I_Day_8_Function 3 | # #2022_07_25_Time_586_ms_(56.94%)_Space_0B_(100.00%) 4 | select distinct(player_id), min(event_date) as first_login 5 | from activity 6 | group by player_id 7 | -------------------------------------------------------------------------------- /src/main/java/g0501_0600/s0570_managers_with_at_least_5_direct_reports/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #Database #2023_05_16_Time_503_ms_(69.79%)_Space_0B_(100.00%) 3 | select e.name 4 | from employee m left join employee e 5 | on m.managerid = e.id 6 | group by e.name 7 | having count(e.name) > 4; 8 | -------------------------------------------------------------------------------- /src/main/java/g1001_1100/s1045_customers_who_bought_all_products/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #Database #2023_06_05_Time_1082_ms_(43.17%)_Space_0B_(100.00%) 3 | select customer_id 4 | from customer 5 | group by customer_id 6 | having count(distinct product_key)=(select count(*) from product); 7 | -------------------------------------------------------------------------------- /src/main/java/g2801_2900/s2882_drop_duplicate_rows/solution.py: -------------------------------------------------------------------------------- 1 | # #Easy #2023_12_23_Time_405_ms_(97.36%)_Space_60.2_MB_(75.25%) 2 | 3 | import pandas as pd 4 | 5 | def dropDuplicateEmails(customers: pd.DataFrame) -> pd.DataFrame: 6 | customers.drop_duplicates(subset='email', keep='first', inplace=True) 7 | return customers 8 | -------------------------------------------------------------------------------- /src/main/java/g1601_1700/s1667_fix_names_in_a_table/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #SQL_I_Day_3_String_Processing_Functions 3 | # #2022_04_22_Time_559_ms_(80.29%)_Space_0B_(100.00%) 4 | select user_id, concat(upper(substring(name, 1, 1)), lower(substring(name, 2))) as name from Users order by user_id 5 | -------------------------------------------------------------------------------- /src/main/java/g1501_1600/s1587_bank_account_summary_ii/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #SQL_I_Day_10_Where #2022_04_11_Time_630_ms_(60.32%)_Space_0B_(100.00%) 3 | select u.name, sum(t.amount) as balance from Users as u join Transactions as t on u.account = t.account group by u.name having balance > 10000 4 | -------------------------------------------------------------------------------- /src/main/java/g1701_1800/s1741_find_total_time_spent_by_each_employee/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #SQL_I_Day_8_Function #2022_05_03_Time_414_ms_(93.27%)_Space_0B_(100.00%) 3 | SELECT event_day AS "day", emp_id, SUM(out_time) - SUM(in_time) AS total_time 4 | FROM Employees 5 | GROUP BY event_day, emp_id 6 | -------------------------------------------------------------------------------- /src/main/java/g1901_2000/s1978_employees_whose_manager_left_the_company/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2023_08_17_Time_719_ms_(64.69%)_Space_0B_(100.00%) 3 | select employee_id from employees where manager_id not in (select distinct (employee_id) 4 | from employees) AND salary < 30000 order by employee_id 5 | -------------------------------------------------------------------------------- /src/main/java/g3401_3500/s3465_find_products_with_valid_serial_numbers/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2025_02_26_Time_292_ms_(90.91%)_Space_0.0_MB_(100.00%) 3 | SELECT * FROM products WHERE description REGEXP 'SN[0-9]{4}-[0-9]{4}$' 4 | OR description REGEXP 'SN[0-9]{4}-[0-9]{4}[^0-9]+' ORDER BY product_id 5 | -------------------------------------------------------------------------------- /src/main/java/g1001_1100/s1075_project_employees_i/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2023_08_12_Time_1524_ms_(75.86%)_Space_0B_(100.00%) 3 | select project_id,round(avg( 4 | experience_years 5 | ),2) as average_years from Project p 6 | left join 7 | Employee e on p.employee_id=e.employee_id group by p.project_id; 8 | -------------------------------------------------------------------------------- /src/main/java/g1101_1200/s1108_defanging_an_ip_address/Solution.java: -------------------------------------------------------------------------------- 1 | package g1101_1200.s1108_defanging_an_ip_address; 2 | 3 | // #Easy #String #2023_06_01_Time_0_ms_(100.00%)_Space_40.6_MB_(55.94%) 4 | 5 | public class Solution { 6 | public String defangIPaddr(String address) { 7 | return address.replace(".", "[.]"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/g1201_1300/s1211_queries_quality_and_percentage/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2023_08_14_Time_1230_ms_(82.08%)_Space_0B_(100.00%) 3 | SELECT query_name, 4 | ROUND(AVG(rating/position), 2) AS quality, 5 | ROUND(AVG((rating<3)*100), 2) AS poor_query_percentage 6 | FROM Queries 7 | GROUP BY query_name 8 | -------------------------------------------------------------------------------- /src/main/java/g0501_0600/s0586_customer_placing_the_largest_number_of_orders/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #LeetCode_Curated_SQL_70 #Database #SQL_I_Day_8_Function 3 | # #2022_08_10_Time_484_ms_(66.42%)_Space_0B_(100.00%) 4 | select customer_number from orders group by customer_number order by count(customer_number) desc limit 1 5 | -------------------------------------------------------------------------------- /src/main/java/g1001_1100/s1025_divisor_game/Solution.java: -------------------------------------------------------------------------------- 1 | package g1001_1100.s1025_divisor_game; 2 | 3 | // #Easy #Dynamic_Programming #Math #Game_Theory #Brainteaser 4 | // #2022_02_26_Time_0_ms_(100.00%)_Space_40.7_MB_(27.10%) 5 | 6 | public class Solution { 7 | public boolean divisorGame(int n) { 8 | return n % 2 == 0; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/g1501_1600/s1551_minimum_operations_to_make_array_equal/Solution.java: -------------------------------------------------------------------------------- 1 | package g1501_1600.s1551_minimum_operations_to_make_array_equal; 2 | 3 | // #Medium #Math #2022_06_22_Time_0_ms_(100.00%)_Space_41.3_MB_(35.47%) 4 | 5 | public class Solution { 6 | public int minOperations(int n) { 7 | return (n * n) / 4; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/g2401_2500/s2413_smallest_even_multiple/Solution.java: -------------------------------------------------------------------------------- 1 | package g2401_2500.s2413_smallest_even_multiple; 2 | 3 | // #Easy #Math #Number_Theory #2022_11_15_Time_0_ms_(100.00%)_Space_40.9_MB_(48.99%) 4 | 5 | public class Solution { 6 | public int smallestEvenMultiple(int n) { 7 | return n % 2 == 0 ? n : n * 2; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/g0101_0200/s0175_combine_two_tables/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #SQL_I_Day_5_Union #2022_06_26_Time_491_ms_(32.30%)_Space_0B_(100.00%) 3 | SELECT 4 | FirstName, 5 | LastName, 6 | City, 7 | State 8 | FROM 9 | Person 10 | LEFT JOIN 11 | Address 12 | USING (PersonId); 13 | -------------------------------------------------------------------------------- /src/main/java/g0301_0400/s0390_elimination_game/Solution.java: -------------------------------------------------------------------------------- 1 | package g0301_0400.s0390_elimination_game; 2 | 3 | // #Medium #Math #Recursion #2022_07_13_Time_4_ms_(81.16%)_Space_42_MB_(71.14%) 4 | 5 | public class Solution { 6 | public int lastRemaining(int n) { 7 | return n == 1 ? 1 : 2 * (n / 2 - lastRemaining(n / 2) + 1); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/g0401_0500/s0476_number_complement/Solution.java: -------------------------------------------------------------------------------- 1 | package g0401_0500.s0476_number_complement; 2 | 3 | // #Easy #Bit_Manipulation #2022_07_20_Time_0_ms_(100.00%)_Space_40.7_MB_(65.79%) 4 | 5 | public class Solution { 6 | public int findComplement(int num) { 7 | return ~num & ((Integer.highestOneBit(num) << 1) - 1); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/g1501_1600/s1527_patients_with_a_condition/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #SQL_I_Day_3_String_Processing_Functions 3 | # #2022_04_12_Time_308_ms_(66.93%)_Space_0B_(100.00%) 4 | Select patient_id,patient_name,conditions from Patients 5 | where conditions like '% DIAB1%' or conditions like 'DIAB1%'; -- NOSONAR 6 | -------------------------------------------------------------------------------- /src/main/java/g1601_1700/s1693_daily_leads_and_partners/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #SQL_I_Day_7_Function #2022_04_13_Time_463_ms_(78.98%)_Space_0B_(100.00%) 3 | select date_id, make_name, COUNT(DISTINCT lead_id) as unique_leads, COUNT(DISTINCT partner_id) as unique_partners from DailySales group by date_id, make_name 4 | -------------------------------------------------------------------------------- /src/main/java/g1801_1900/s1873_calculate_special_bonus/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #SQL_I_Day_2_Select_and_Order #2022_05_12_Time_543_ms_(71.60%)_Space_0B_(100.00%) 3 | select employee_id, 4 | CASE 5 | WHEN employee_id%2 = 1 and name NOT LIKE'M%' 6 | THEN salary 7 | ELSE 0 8 | END AS bonus 9 | from employees 10 | -------------------------------------------------------------------------------- /src/main/java/g2701_2800/s2769_find_the_maximum_achievable_number/Solution.java: -------------------------------------------------------------------------------- 1 | package g2701_2800.s2769_find_the_maximum_achievable_number; 2 | 3 | // #Easy #Math #2023_09_21_Time_1_ms_(100.00%)_Space_40.4_MB_(26.03%) 4 | 5 | public class Solution { 6 | public int theMaximumAchievableX(int num, int t) { 7 | return num + t * 2; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/g2801_2900/s2877_create_a_dataframe_from_list/solution.py: -------------------------------------------------------------------------------- 1 | # #Easy #2023_12_22_Time_406_ms_(82.57%)_Space_59.2_MB_(81.15%) 2 | 3 | import pandas as pd 4 | 5 | def createDataframe(student_data: List[List[int]]) -> pd.DataFrame: 6 | column_name = ['student_id','age'] 7 | result = pd.DataFrame(student_data, columns=column_name) 8 | return result 9 | -------------------------------------------------------------------------------- /src/main/java/g0101_0200/s0183_customers_who_never_order/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #SQL_I_Day_1_Select #2022_06_27_Time_376_ms_(98.73%)_Space_0B_(100.00%) 3 | SELECT 4 | c.Name AS Customers 5 | FROM 6 | Customers AS c 7 | LEFT JOIN Orders AS o ON c.Id = o.CustomerId 8 | WHERE 9 | o.CustomerId IS NULL; 10 | -------------------------------------------------------------------------------- /src/main/java/g1001_1100/s1050_actors_and_directors_who_cooperated_at_least_three_times/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #LeetCode_Curated_SQL_70 #Database #SQL_I_Day_10_Where 3 | # #2022_05_24_Time_344_ms_(76.48%)_Space_0B_(100.00%) 4 | SELECT actor_id, director_id 5 | FROM ActorDirector 6 | GROUP BY actor_id, director_id 7 | HAVING COUNT(*) > 2 8 | -------------------------------------------------------------------------------- /src/main/java/g1301_1400/s1393_capital_gainloss/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #LeetCode_Curated_SQL_70 #Database #SQL_I_Day_9_Control_of_Flow 3 | # #2022_07_26_Time_428_ms_(92.01%)_Space_0B_(100.00%) 4 | SELECT stock_name, SUM(CASE WHEN operation='Sell' THEN price ELSE -price END) AS capital_gain_loss 5 | FROM Stocks GROUP BY stock_name; 6 | -------------------------------------------------------------------------------- /src/main/java/g2801_2900/s2885_rename_columns/solution.py: -------------------------------------------------------------------------------- 1 | # #Easy #2023_12_23_Time_467_ms_(68.13%)_Space_60.7_MB_(15.08%) 2 | 3 | import pandas as pd 4 | 5 | def renameColumns(students: pd.DataFrame) -> pd.DataFrame: 6 | students.rename(columns={'id': 'student_id', 'first': 'first_name', 'last': 'last_name', 'age': 'age_in_years'}, inplace=True) 7 | return students 8 | -------------------------------------------------------------------------------- /src/main/java/g0401_0500/s0461_hamming_distance/Solution.java: -------------------------------------------------------------------------------- 1 | package g0401_0500.s0461_hamming_distance; 2 | 3 | // #Easy #Bit_Manipulation #Udemy_Bit_Manipulation 4 | // #2022_07_19_Time_0_ms_(100.00%)_Space_40.9_MB_(60.77%) 5 | 6 | public class Solution { 7 | public int hammingDistance(int x, int y) { 8 | return Integer.bitCount(x ^ y); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/g3601_3700/s3658_gcd_of_odd_and_even_sums/Solution.java: -------------------------------------------------------------------------------- 1 | package g3601_3700.s3658_gcd_of_odd_and_even_sums; 2 | 3 | // #Easy #Math #Number_Theory #Weekly_Contest_464 4 | // #2025_09_26_Time_0_ms_(100.00%)_Space_41.43_MB_(15.15%) 5 | 6 | public class Solution { 7 | public int gcdOfOddEvenSums(int n) { 8 | return (n < 0) ? -n : n; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/g1001_1100/s1070_product_sales_analysis_iii/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #Database #2023_08_12_Time_1693_ms_(90.17%)_Space_0B_(100.00%) 3 | WITH ab AS (SELECT *, RANK() OVER(PARTITION BY product_id ORDER BY sale_year ASC) AS rk 4 | FROM Sales) 5 | SELECT product_id, sale_year AS first_year, quantity, price 6 | FROM ab 7 | WHERE rk = 1; 8 | -------------------------------------------------------------------------------- /src/main/java/g1401_1500/s1407_top_travellers/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #LeetCode_Curated_SQL_70 #Database #SQL_I_Day_9_Control_of_Flow 3 | # #2022_03_28_Time_682_ms_(70.16%)_Space_0B_(100.00%) 4 | SELECT U.NAME , COALESCE(SUM(R.DISTANCE),0) AS travelled_distance 5 | FROM USERS U LEFT JOIN RIDES R ON U.ID=R.USER_ID 6 | GROUP BY 1 ORDER BY 2 DESC , 1 ASC 7 | -------------------------------------------------------------------------------- /src/main/java/g2701_2800/s2703_return_length_of_arguments_passed/solution.ts: -------------------------------------------------------------------------------- 1 | // #Easy #2025_02_26_Time_50_ms_(82.03%)_Space_54.95_MB_(7.19%) 2 | 3 | type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue }; 4 | 5 | function argumentsLength(...args: JSONValue[]): number { 6 | return args.length 7 | } 8 | 9 | export { argumentsLength } 10 | -------------------------------------------------------------------------------- /src/main/java/g0101_0200/s0197_rising_temperature/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #SQL_I_Day_6_Union #2022_06_28_Time_342_ms_(93.76%)_Space_0B_(100.00%) 3 | SELECT SecondDate.id as Id 4 | FROM Weather SecondDate JOIN Weather FirstDate 5 | ON ADDDATE(FirstDate.recordDate,1) = SecondDate.recordDate 6 | AND SecondDate.temperature > FirstDate.temperature; 7 | -------------------------------------------------------------------------------- /src/main/java/g0301_0400/s0319_bulb_switcher/Solution.java: -------------------------------------------------------------------------------- 1 | package g0301_0400.s0319_bulb_switcher; 2 | 3 | // #Medium #Math #Brainteaser #2022_07_08_Time_0_ms_(100.00%)_Space_41.1_MB_(27.19%) 4 | 5 | public class Solution { 6 | public int bulbSwitch(int n) { 7 | if (n < 2) { 8 | return n; 9 | } 10 | return (int) Math.sqrt(n); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/g2601_2700/s2621_sleep/solution.ts: -------------------------------------------------------------------------------- 1 | // #Easy #2023_08_31_Time_40_ms_(99.59%)_Space_42.3_MB_(77.98%) 2 | 3 | async function sleep(millis: number): Promise { 4 | await new Promise((resolve) => setTimeout(resolve, millis)) 5 | } 6 | 7 | /* 8 | * let t = Date.now() 9 | * sleep(100).then(() => console.log(Date.now() - t)) // 100 10 | */ 11 | 12 | export { sleep } 13 | -------------------------------------------------------------------------------- /src/main/java/g3301_3400/s3374_first_letter_capitalization_ii/solution.py: -------------------------------------------------------------------------------- 1 | # #Hard #Database #2024_12_06_Time_261_ms_(84.21%)_Space_66.3_MB_(17.89%) 2 | 3 | import pandas as pd 4 | 5 | def capitalize_content(user_content): 6 | user_content['converted_text'] = (user_content.content_text.apply(lambda x: x.title())) 7 | return user_content.rename(columns={'content_text': 'original_text'}) 8 | -------------------------------------------------------------------------------- /src/main/java/g0101_0200/s0181_employees_earning_more_than_their_managers/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2022_06_27_Time_315_ms_(94.44%)_Space_0B_(100.00%) 3 | SELECT 4 | a.Name AS Employee 5 | FROM 6 | Employee a 7 | LEFT JOIN Employee b ON a.ManagerId = b.Id 8 | WHERE 9 | a.Salary > b.Salary 10 | AND a.ManagerId IS NOT NULL; 11 | -------------------------------------------------------------------------------- /src/main/java/g2501_2600/s2579_count_total_number_of_colored_cells/Solution.java: -------------------------------------------------------------------------------- 1 | package g2501_2600.s2579_count_total_number_of_colored_cells; 2 | 3 | // #Medium #Math #2023_08_22_Time_0_ms_(100.00%)_Space_39.2_MB_(60.33%) 4 | 5 | public class Solution { 6 | public long coloredCells(int n) { 7 | return (long) Math.pow(n, 2) + (long) Math.pow(n - (double) 1, 2); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/g2701_2800/s2724_sort_by/solution.ts: -------------------------------------------------------------------------------- 1 | // #Easy #2023_09_19_Time_124_ms_(86.52%)_Space_57_MB_(53.08%) 2 | 3 | type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue } 4 | type Fn = (value: JSONValue) => number 5 | 6 | const sortBy = (arr: JSONValue[], fn: Fn): JSONValue[] => [...arr].sort((a, b) => (fn(a) > fn(b) ? 1 : -1)) 7 | 8 | export { sortBy } 9 | -------------------------------------------------------------------------------- /src/main/java/g1501_1600/s1581_customer_who_visited_but_did_not_make_any_transactions/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #SQL_I_Day_5_Union #2022_04_12_Time_1039_ms_(76.99%)_Space_0B_(100.00%) 3 | select customer_id, COUNT(*) as count_no_trans 4 | from visits v left join transactions t 5 | on v.visit_id = t.visit_id 6 | where transaction_id is null 7 | group by customer_id 8 | -------------------------------------------------------------------------------- /src/main/java/g0101_0200/s0177_nth_highest_salary/script.sql: -------------------------------------------------------------------------------- 1 | CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT 2 | BEGIN 3 | DECLARE M INT; 4 | SET M=N-1; 5 | RETURN ( 6 | # Write your MySQL query statement below. 7 | # #Medium #Database #2022_06_26_Time_342_ms_(71.87%)_Space_0B_(100.00%) 8 | SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT M, 1 9 | ); 10 | END 11 | -------------------------------------------------------------------------------- /src/main/java/g0101_0200/s0180_consecutive_numbers/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #Database #2024_07_15_Time_469_ms_(89.19%)_Space_0B_(100.00%) 3 | SELECT DISTINCT 4 | l1.num AS ConsecutiveNums 5 | FROM 6 | Logs l1 7 | JOIN Logs l2 ON l1.id = l2.id - 1 8 | JOIN Logs l3 ON l1.id = l3.id - 2 9 | WHERE 10 | l1.num = l2.num 11 | AND l2.num = l3.num; 12 | -------------------------------------------------------------------------------- /src/main/java/g0801_0900/s0836_rectangle_overlap/Solution.java: -------------------------------------------------------------------------------- 1 | package g0801_0900.s0836_rectangle_overlap; 2 | 3 | // #Easy #Math #Geometry #2022_03_24_Time_0_ms_(100.00%)_Space_41.6_MB_(35.43%) 4 | 5 | public class Solution { 6 | public boolean isRectangleOverlap(int[] rec1, int[] rec2) { 7 | return rec1[0] < rec2[2] && rec2[0] < rec1[2] && rec1[1] < rec2[3] && rec2[1] < rec1[3]; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/g1401_1500/s1484_group_sold_products_by_the_date/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #LeetCode_Curated_SQL_70 #Database #SQL_I_Day_3_String_Processing_Functions 3 | # #2022_04_06_Time_395_ms_(77.20%)_Space_0B_(100.00%) 4 | SELECT sell_date, COUNT(DISTINCT(product)) as num_sold, GROUP_CONCAT(DISTINCT(product) ORDER BY product) as products 5 | FROM Activities 6 | GROUP BY sell_date 7 | -------------------------------------------------------------------------------- /src/main/java/g2601_2700/s2635_apply_transform_over_each_element_in_array/solution.ts: -------------------------------------------------------------------------------- 1 | // #Easy #2023_08_31_Time_43_ms_(98.46%)_Space_42.2_MB_(92.83%) 2 | 3 | function map(arr: number[], fn: (n: number, i: number) => number): number[] { 4 | const res: number[] = [] 5 | for (let i = 0; i < arr.length; i++) { 6 | res.push(fn(arr[i], i)) 7 | } 8 | return res 9 | } 10 | 11 | export { map } 12 | -------------------------------------------------------------------------------- /src/main/java/g3201_3300/s3220_odd_and_even_transactions/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #Database #2024_07_23_Time_248_ms_(85.85%)_Space_0B_(100.00%) 3 | select transaction_date, 4 | sum(case when amount%2<>0 then amount else 0 end) as odd_sum, 5 | sum(case when amount%2=0 then amount else 0 end) as even_sum from transactions 6 | group by transaction_date order by transaction_date asc; 7 | -------------------------------------------------------------------------------- /src/main/java/g0501_0600/s0504_base_7/readme.md: -------------------------------------------------------------------------------- 1 | 504\. Base 7 2 | 3 | Easy 4 | 5 | Given an integer `num`, return _a string of its **base 7** representation_. 6 | 7 | **Example 1:** 8 | 9 | **Input:** num = 100 10 | 11 | **Output:** "202" 12 | 13 | **Example 2:** 14 | 15 | **Input:** num = -7 16 | 17 | **Output:** "-10" 18 | 19 | **Constraints:** 20 | 21 | * -107 <= num <= 107 -------------------------------------------------------------------------------- /src/main/java/g0601_0700/s0607_sales_person/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #LeetCode_Curated_SQL_70 #Database #SQL_I_Day_6_Union 3 | # #2022_06_03_Time_1046_ms_(86.04%)_Space_0B_(100.00%) 4 | SELECT NAME 5 | FROM 6 | SALESPERSON 7 | WHERE SALES_ID NOT IN 8 | ( 9 | SELECT O.SALES_ID FROM ORDERS AS O LEFT JOIN COMPANY C 10 | ON O.COM_ID = C.COM_ID 11 | WHERE C.NAME = 'RED' 12 | ) 13 | -------------------------------------------------------------------------------- /src/main/java/g1201_1300/s1204_last_person_to_fit_in_the_bus/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #Database #2023_08_14_Time_1581_ms_(84.10%)_Space_0B_(100.00%) 3 | WITH ctx AS( 4 | SELECT person_name, SUM(weight) OVER(ORDER BY turn ASC) AS running_sum 5 | FROM queue 6 | ) 7 | 8 | SELECT person_name 9 | FROM ctx 10 | WHERE running_sum <= 1000 11 | ORDER BY running_sum DESC 12 | LIMIT 1; 13 | -------------------------------------------------------------------------------- /src/main/java/g2401_2500/s2481_minimum_cuts_to_divide_a_circle/Solution.java: -------------------------------------------------------------------------------- 1 | package g2401_2500.s2481_minimum_cuts_to_divide_a_circle; 2 | 3 | // #Easy #Math #Geometry #2023_01_25_Time_0_ms_(100.00%)_Space_39.2_MB_(87.50%) 4 | 5 | public class Solution { 6 | public int numberOfCuts(int n) { 7 | if (n == 1) { 8 | return 0; 9 | } 10 | return n % 2 > 0 ? n : n / 2; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/g2101_2200/s2119_a_number_after_a_double_reversal/Solution.java: -------------------------------------------------------------------------------- 1 | package g2101_2200.s2119_a_number_after_a_double_reversal; 2 | 3 | // #Easy #Math #2022_06_01_Time_0_ms_(100.00%)_Space_40.4_MB_(67.63%) 4 | 5 | public class Solution { 6 | public boolean isSameAfterReversals(int num) { 7 | if (num == 0) { 8 | return true; 9 | } 10 | return num % 10 != 0; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/g2201_2300/s2236_root_equals_sum_of_children/Solution.java: -------------------------------------------------------------------------------- 1 | package g2201_2300.s2236_root_equals_sum_of_children; 2 | 3 | // #Easy #Tree #Binary_Tree #2022_06_10_Time_0_ms_(100.00%)_Space_40.3_MB_(73.85%) 4 | 5 | import com_github_leetcode.TreeNode; 6 | 7 | public class Solution { 8 | public boolean checkTree(TreeNode root) { 9 | return root.left.val + root.right.val == root.val; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/g3401_3500/s3492_maximum_containers_on_a_ship/Solution.java: -------------------------------------------------------------------------------- 1 | package g3401_3500.s3492_maximum_containers_on_a_ship; 2 | 3 | // #Easy #Math #2025_03_24_Time_0_ms_(100.00%)_Space_40.73_MB_(100.00%) 4 | 5 | public class Solution { 6 | public int maxContainers(int n, int w, int maxWeight) { 7 | int c = n * n; 8 | int count = maxWeight / w; 9 | return Math.min(c, count); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/g0601_0700/s0608_tree_node/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #LeetCode_Curated_SQL_70 #Database #SQL_I_Day_4_Union_and_Select 3 | # #2022_04_14_Time_347_ms_(95.17%)_Space_0B_(100.00%) 4 | select id,case 5 | when p_id is null then 'Root' 6 | when id in (select p_id from tree) then 'Inner' 7 | else 'Leaf' 8 | end as type 9 | from tree; 10 | -------------------------------------------------------------------------------- /src/main/java/g1101_1200/s1141_user_activity_for_the_past_30_days_i/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #LeetCode_Curated_SQL_70 #Database #SQL_I_Day_7_Function 3 | # #2023_06_01_Time_849_ms_(72.54%)_Space_0B_(100.00%) 4 | SELECT activity_date as "day", COUNT(DISTINCT user_id) AS active_users 5 | FROM activity 6 | WHERE (activity_date > '2019-06-27' AND activity_date <= '2019-07-27') 7 | GROUP BY activity_date; 8 | -------------------------------------------------------------------------------- /src/main/java/g2501_2600/s2549_count_distinct_numbers_on_board/Solution.java: -------------------------------------------------------------------------------- 1 | package g2501_2600.s2549_count_distinct_numbers_on_board; 2 | 3 | // #Easy #Array #Hash_Table #Math #Simulation #2023_08_15_Time_0_ms_(100.00%)_Space_39.2_MB_(75.23%) 4 | 5 | public class Solution { 6 | public int distinctIntegers(int n) { 7 | if (n == 1) { 8 | return 1; 9 | } 10 | return n - 1; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/g2601_2700/s2619_array_prototype_last/solution.test.ts: -------------------------------------------------------------------------------- 1 | // tslint:disable:no-magic-numbers 2 | import 'src/main/java/g2601_2700/s2619_array_prototype_last/solution' 3 | import { expect, test } from 'vitest' 4 | 5 | test('last', () => { 6 | let nums = [null, {}, 3].last() 7 | expect(nums).toEqual(3) 8 | }) 9 | 10 | test('last2', () => { 11 | let nums = [].last() 12 | expect(nums).toEqual(-1) 13 | }) 14 | -------------------------------------------------------------------------------- /src/main/java/g0501_0600/s0585_investments_in_2016/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #Database #2023_05_18_Time_729_ms_(99.22%)_Space_0B_(100.00%) 3 | select round(sum(tiv_2016),2) tiv_2016 from insurance i1 4 | where tiv_2015 in (select tiv_2015 from insurance i2 5 | where i1.pid != i2.pid) 6 | and (lat, lon) not in (select lat, lon from insurance i3 7 | where i3.pid != i1.pid) 8 | -------------------------------------------------------------------------------- /src/main/java/g2601_2700/s2666_allow_one_function_call/solution.ts: -------------------------------------------------------------------------------- 1 | // #Easy #2023_09_09_Time_50_ms_(88.35%)_Space_43.1_MB_(19.45%) 2 | 3 | type Fn = (...args: any[]) => any 4 | 5 | function once(fn: Fn): Fn { 6 | let wasCalled = false 7 | return function (...args) { 8 | if (!wasCalled) { 9 | wasCalled = true 10 | return fn(...args) 11 | } 12 | } 13 | } 14 | 15 | export { once } 16 | -------------------------------------------------------------------------------- /src/main/java/g3001_3100/s3021_alice_and_bob_playing_flower_game/Solution.java: -------------------------------------------------------------------------------- 1 | package g3001_3100.s3021_alice_and_bob_playing_flower_game; 2 | 3 | // #Medium #Math #2024_02_29_Time_0_ms_(100.00%)_Space_40.8_MB_(25.85%) 4 | 5 | public class Solution { 6 | public long flowerGame(long n, long m) { 7 | long ans = 0; 8 | ans += ((n + 1) / 2) * (m / 2) + ((m + 1) / 2) * (n / 2); 9 | return ans; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/g3501_3600/s3513_number_of_unique_xor_triplets_i/Solution.java: -------------------------------------------------------------------------------- 1 | package g3501_3600.s3513_number_of_unique_xor_triplets_i; 2 | 3 | // #Medium #Array #Math #Bit_Manipulation #2025_04_14_Time_1_ms_(100.00%)_Space_62.16_MB_(100.00%) 4 | 5 | public class Solution { 6 | public int uniqueXorTriplets(int[] nums) { 7 | int n = nums.length; 8 | return n < 3 ? n : Integer.highestOneBit(n) << 1; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/g2701_2800/s2704_to_be_or_not_to_be/solution.test.ts: -------------------------------------------------------------------------------- 1 | // tslint:disable:no-magic-numbers 2 | import { expect as expectFunc } from 'src/main/java/g2701_2800/s2704_to_be_or_not_to_be/solution' 3 | import { expect, test } from 'vitest' 4 | 5 | test('expect', () => { 6 | expect(expectFunc(5).toBe(5)).toEqual(true) 7 | }) 8 | 9 | test('expect2', () => { 10 | expect(expectFunc(5).notToBe(null)).toEqual(true) 11 | }) 12 | -------------------------------------------------------------------------------- /src/main/java/g2501_2600/s2546_apply_bitwise_operations_to_make_strings_equal/Solution.java: -------------------------------------------------------------------------------- 1 | package g2501_2600.s2546_apply_bitwise_operations_to_make_strings_equal; 2 | 3 | // #Medium #String #Bit_Manipulation #2023_08_15_Time_0_ms_(100.00%)_Space_44.3_MB_(87.14%) 4 | 5 | public class Solution { 6 | public boolean makeStringsEqual(String s, String target) { 7 | return s.contains("1") == target.contains("1"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/g2801_2900/s2806_account_balance_after_rounded_purchase/Solution.java: -------------------------------------------------------------------------------- 1 | package g2801_2900.s2806_account_balance_after_rounded_purchase; 2 | 3 | // #Easy #Math #2023_09_25_Time_0_ms_(100.00%)_Space_39.2_MB_(64.97%) 4 | 5 | public class Solution { 6 | public int accountBalanceAfterPurchase(int purchaseAmount) { 7 | int x = (int) ((purchaseAmount + 5) / (double) 10) * 10; 8 | return 100 - x; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/g2601_2700/s2651_calculate_delayed_arrival_time/Solution.java: -------------------------------------------------------------------------------- 1 | package g2601_2700.s2651_calculate_delayed_arrival_time; 2 | 3 | // #Easy #Math #2023_09_06_Time_0_ms_(100.00%)_Space_39.6_MB_(47.38%) 4 | 5 | public class Solution { 6 | public int findDelayedArrivalTime(int ar, int de) { 7 | if (ar + de >= 24) { 8 | return Math.abs(ar + de - 24); 9 | } 10 | return ar + de; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/g2701_2800/s2723_add_two_promises/solution.ts: -------------------------------------------------------------------------------- 1 | // #Easy #2023_09_18_Time_53_ms_(95.40%)_Space_43.2_MB_(24.42%) 2 | 3 | async function addTwoPromises(promise1: Promise, promise2: Promise): Promise { 4 | return (await promise1) + (await promise2) 5 | } 6 | 7 | /* 8 | * addTwoPromises(Promise.resolve(2), Promise.resolve(2)) 9 | * .then(console.log); // 4 10 | */ 11 | 12 | export { addTwoPromises } 13 | -------------------------------------------------------------------------------- /src/main/java/g3201_3300/s3210_find_the_encrypted_string/Solution.java: -------------------------------------------------------------------------------- 1 | package g3201_3300.s3210_find_the_encrypted_string; 2 | 3 | // #Easy #String #2024_07_09_Time_1_ms_(100.00%)_Space_42.8_MB_(34.96%) 4 | 5 | public class Solution { 6 | public String getEncryptedString(String s, int k) { 7 | int n = s.length(); 8 | int localK = k % n; 9 | return s.substring(localK, n) + s.substring(0, localK); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/g0301_0400/s0371_sum_of_two_integers/readme.md: -------------------------------------------------------------------------------- 1 | 371\. Sum of Two Integers 2 | 3 | Medium 4 | 5 | Given two integers `a` and `b`, return _the sum of the two integers without using the operators_ `+` _and_ `-`. 6 | 7 | **Example 1:** 8 | 9 | **Input:** a = 1, b = 2 10 | 11 | **Output:** 3 12 | 13 | **Example 2:** 14 | 15 | **Input:** a = 2, b = 3 16 | 17 | **Output:** 5 18 | 19 | **Constraints:** 20 | 21 | * `-1000 <= a, b <= 1000` -------------------------------------------------------------------------------- /src/main/java/g1501_1600/s1556_thousand_separator/readme.md: -------------------------------------------------------------------------------- 1 | 1556\. Thousand Separator 2 | 3 | Easy 4 | 5 | Given an integer `n`, add a dot (".") as the thousands separator and return it in string format. 6 | 7 | **Example 1:** 8 | 9 | **Input:** n = 987 10 | 11 | **Output:** "987" 12 | 13 | **Example 2:** 14 | 15 | **Input:** n = 1234 16 | 17 | **Output:** "1.234" 18 | 19 | **Constraints:** 20 | 21 | * 0 <= n <= 231 - 1 -------------------------------------------------------------------------------- /src/main/java/g2301_2400/s2317_maximum_xor_after_operations/Solution.java: -------------------------------------------------------------------------------- 1 | package g2301_2400.s2317_maximum_xor_after_operations; 2 | 3 | // #Medium #Array #Math #Bit_Manipulation #2022_06_26_Time_1_ms_(100.00%)_Space_53.3_MB_(100.00%) 4 | 5 | public class Solution { 6 | public int maximumXOR(int[] nums) { 7 | int max = 0; 8 | for (int n : nums) { 9 | max |= n; 10 | } 11 | return max; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/g2601_2700/s2634_filter_elements_from_array/solution.ts: -------------------------------------------------------------------------------- 1 | // #Easy #2023_08_31_Time_44_ms_(98.04%)_Space_42.7_MB_(69.67%) 2 | 3 | function filter(arr: number[], fn: (n: number, i: number) => boolean): number[] { 4 | const filteredArr: number[] = [] 5 | 6 | for (let i = 0; i < arr.length; i++) { 7 | if (fn(arr[i], i)) filteredArr.push(arr[i]) 8 | } 9 | 10 | return filteredArr 11 | } 12 | 13 | export { filter } 14 | -------------------------------------------------------------------------------- /src/main/java/g0501_0600/s0550_game_play_analysis_iv/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #Database #2023_05_16_Time_685_ms_(100.00%)_Space_0B_(100.00%) 3 | SELECT ROUND(COUNT(t2.player_id)/CAST(COUNT(t1.player_id) AS DECIMAL),2) AS fraction 4 | FROM 5 | (SELECT player_id, MIN(event_date) AS first_login FROM Activity GROUP BY player_id) t1 LEFT JOIN Activity t2 6 | ON t1.player_id = t2.player_id AND t1.first_login = t2.event_date - 1 7 | -------------------------------------------------------------------------------- /src/main/java/g0601_0700/s0626_exchange_seats/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #Database #2022_03_21_Time_274_ms_(65.75%)_Space_0B_(100.00%) 3 | select 4 | id, 5 | case when id % 2 = 1 and lead(student) over (order by id) is null then student 6 | when id % 2 = 1 then lead(student) over (order by id) 7 | else lag(student) over (order by id) 8 | end as student 9 | from seat 10 | order by id asc 11 | -------------------------------------------------------------------------------- /src/main/java/g1701_1800/s1791_find_center_of_star_graph/Solution.java: -------------------------------------------------------------------------------- 1 | package g1701_1800.s1791_find_center_of_star_graph; 2 | 3 | // #Easy #Graph #2022_05_03_Time_0_ms_(100.00%)_Space_71_MB_(77.85%) 4 | 5 | public class Solution { 6 | public int findCenter(int[][] edges) { 7 | if (edges[0][0] == edges[1][0] || edges[0][0] == edges[1][1]) { 8 | return edges[0][0]; 9 | } 10 | return edges[0][1]; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/g1901_2000/s1965_employees_with_missing_information/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #SQL_I_Day_4_Union_and_Select #2022_05_22_Time_617_ms_(30.40%)_Space_0B_(100.00%) 3 | select employee_id 4 | from employees 5 | where employee_id not in (select employee_id from salaries) 6 | UNION 7 | select employee_id 8 | from salaries 9 | where employee_id not in (select employee_id from Employees) 10 | order by 1 11 | -------------------------------------------------------------------------------- /src/main/java/g2601_2700/s2620_counter/solution.ts: -------------------------------------------------------------------------------- 1 | // #Easy #2023_08_31_Time_43_ms_(98.60%)_Space_42.2_MB_(91.27%) 2 | 3 | function createCounter(n: number): () => number { 4 | const fun = function () { 5 | n++ 6 | return n - 1 7 | } 8 | return fun 9 | } 10 | 11 | /* 12 | * const counter = createCounter(10) 13 | * counter() // 10 14 | * counter() // 11 15 | * counter() // 12 16 | */ 17 | 18 | export { createCounter } 19 | -------------------------------------------------------------------------------- /src/main/java/g3301_3400/s3370_smallest_number_with_all_set_bits/Solution.java: -------------------------------------------------------------------------------- 1 | package g3301_3400.s3370_smallest_number_with_all_set_bits; 2 | 3 | // #Easy #Math #Bit_Manipulation #2024_12_03_Time_0_ms_(100.00%)_Space_41.1_MB_(45.50%) 4 | 5 | public class Solution { 6 | public int smallestNumber(int n) { 7 | int res = 1; 8 | while (res < n) { 9 | res = res * 2 + 1; 10 | } 11 | return res; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/g0201_0300/s0258_add_digits/Solution.java: -------------------------------------------------------------------------------- 1 | package g0201_0300.s0258_add_digits; 2 | 3 | // #Easy #Math #Simulation #Number_Theory #2022_07_05_Time_1_ms_(100.00%)_Space_39.3_MB_(98.44%) 4 | 5 | public class Solution { 6 | public int addDigits(int num) { 7 | if (num == 0) { 8 | return 0; 9 | } 10 | if (num % 9 == 0) { 11 | return 9; 12 | } 13 | return num % 9; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g1601_1700/s1633_percentage_of_users_attended_a_contest/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2023_08_16_Time_1550_ms_(95.68%)_Space_0B_(100.00%) 3 | SELECT r.contest_id, 4 | ROUND(COUNT(r.user_id) / (SELECT COUNT(user_id) FROM Users) * 100,2) as percentage 5 | FROM Users u LEFT JOIN Register r ON u.user_id=r.user_id 6 | WHERE contest_id IS NOT NULL 7 | GROUP BY r.contest_id 8 | ORDER BY percentage DESC, contest_id ASC 9 | -------------------------------------------------------------------------------- /src/main/java/g2601_2700/s2626_array_reduce_transformation/solution.ts: -------------------------------------------------------------------------------- 1 | // #Easy #2023_08_31_Time_52_ms_(91.40%)_Space_44.2_MB_(82.03%) 2 | 3 | type Fn = (accum: number, curr: number) => number 4 | 5 | function reduce(nums: number[], fn: Fn, init: number): number { 6 | let accumulator = init 7 | nums.forEach((num) => { //NOSONAR 8 | accumulator = fn(accumulator, num) 9 | }) 10 | return accumulator 11 | } 12 | 13 | export { reduce } 14 | -------------------------------------------------------------------------------- /src/main/java/g3101_3200/s3178_find_the_child_who_has_the_ball_after_k_seconds/Solution.java: -------------------------------------------------------------------------------- 1 | package g3101_3200.s3178_find_the_child_who_has_the_ball_after_k_seconds; 2 | 3 | // #Easy #Math #Simulation #2024_06_12_Time_0_ms_(100.00%)_Space_40.4_MB_(93.82%) 4 | 5 | public class Solution { 6 | public int numberOfChild(int n, int k) { 7 | int bigN = 2 * n - 2; 8 | int x = k % bigN; 9 | return (x < n) ? x : bigN - x; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/g0101_0200/s0176_second_highest_salary/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #Database #SQL_I_Day_4_Union_and_Select 3 | # #2022_07_10_Time_225_ms_(73.10%)_Space_0B_(100.00%) 4 | SELECT 5 | IFNULL( 6 | ( 7 | SELECT DISTINCT Salary 8 | FROM Employee 9 | ORDER BY Salary DESC 10 | LIMIT 1 OFFSET 1 11 | ), 12 | NULL 13 | ) AS SecondHighestSalary; 14 | -------------------------------------------------------------------------------- /src/main/java/g0201_0300/s0233_number_of_digit_one/readme.md: -------------------------------------------------------------------------------- 1 | 233\. Number of Digit One 2 | 3 | Hard 4 | 5 | Given an integer `n`, count _the total number of digit_ `1` _appearing in all non-negative integers less than or equal to_ `n`. 6 | 7 | **Example 1:** 8 | 9 | **Input:** n = 13 10 | 11 | **Output:** 6 12 | 13 | **Example 2:** 14 | 15 | **Input:** n = 0 16 | 17 | **Output:** 0 18 | 19 | **Constraints:** 20 | 21 | * 0 <= n <= 109 -------------------------------------------------------------------------------- /src/main/java/g1001_1100/s1037_valid_boomerang/Solution.java: -------------------------------------------------------------------------------- 1 | package g1001_1100.s1037_valid_boomerang; 2 | 3 | // #Easy #Array #Math #Geometry #2022_02_27_Time_0_ms_(100.00%)_Space_41.7_MB_(21.15%) 4 | 5 | public class Solution { 6 | public boolean isBoomerang(int[][] points) { 7 | return (points[1][1] - points[0][1]) * (points[2][0] - points[0][0]) 8 | != (points[2][1] - points[0][1]) * (points[1][0] - points[0][0]); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/g2601_2700/s2619_array_prototype_last/solution.ts: -------------------------------------------------------------------------------- 1 | // #Easy #2023_08_31_Time_41_ms_(98.99%)_Space_42_MB_(96.92%) 2 | 3 | declare global { 4 | interface Array { 5 | last(): T | -1 6 | } 7 | } 8 | 9 | Array.prototype.last = function () { //NOSONAR 10 | return this.length !== 0 ? this[this.length - 1] : -1 //NOSONAR 11 | } 12 | 13 | /* 14 | * const arr = [1, 2, 3]; 15 | * arr.last(); // 3 16 | */ 17 | 18 | export {} //NOSONAR 19 | -------------------------------------------------------------------------------- /src/main/java/g2601_2700/s2683_neighboring_bitwise_xor/Solution.java: -------------------------------------------------------------------------------- 1 | package g2601_2700.s2683_neighboring_bitwise_xor; 2 | 3 | // #Medium #Array #Bit_Manipulation #2023_09_12_Time_2_ms_(100.00%)_Space_59.9_MB_(62.03%) 4 | 5 | public class Solution { 6 | public boolean doesValidArrayExist(int[] derived) { 7 | int xor = 0; 8 | for (int j : derived) { 9 | xor = xor ^ j; 10 | } 11 | return xor == 0; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/g2601_2700/s2627_debounce/solution.test.ts: -------------------------------------------------------------------------------- 1 | // tslint:disable:no-magic-numbers 2 | import { debounce } from 'src/main/java/g2601_2700/s2627_debounce/solution' 3 | import { expect, test } from 'vitest' 4 | 5 | test('debounce', () => { 6 | const log = debounce(console.log, 100) 7 | log('Hello') 8 | // cancelled 9 | log('Hello') 10 | // cancelled 11 | log('Hello') 12 | // Logged at t=100ms 13 | expect(1).toEqual(1) 14 | }) 15 | -------------------------------------------------------------------------------- /src/test/java/g2701_2800/s2727_is_object_empty/solution.test.ts: -------------------------------------------------------------------------------- 1 | import { isEmpty } from 'src/main/java/g2701_2800/s2727_is_object_empty/solution' 2 | import { expect, test } from 'vitest' 3 | 4 | test('isEmpty', () => { 5 | expect(isEmpty({ x: 5, y: 42 })).toEqual(false) 6 | }) 7 | 8 | test('isEmpty2', () => { 9 | expect(isEmpty({})).toEqual(true) 10 | }) 11 | 12 | test('isEmpty3', () => { 13 | expect(isEmpty([null, false, 0])).toEqual(false) 14 | }) 15 | -------------------------------------------------------------------------------- /src/main/java/g1201_1300/s1251_average_selling_price/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2023_08_14_Time_1413_ms_(86.28%)_Space_0B_(100.00%) 3 | SELECT us.product_id, 4 | ROUND(SUM(p.price * us.units) / SUM(us.units), 2) AS average_price 5 | FROM UnitsSold us 6 | JOIN Prices p 7 | ON us.product_id = p.product_id 8 | AND us.purchase_date BETWEEN p.start_date AND p.end_date 9 | GROUP BY us.product_id; 10 | -------------------------------------------------------------------------------- /src/main/java/g3001_3100/s3091_apply_operations_to_make_sum_of_array_greater_than_or_equal_to_k/Solution.java: -------------------------------------------------------------------------------- 1 | package g3001_3100.s3091_apply_operations_to_make_sum_of_array_greater_than_or_equal_to_k; 2 | 3 | // #Medium #Math #Greedy #Enumeration #2024_04_18_Time_0_ms_(100.00%)_Space_40.6_MB_(62.55%) 4 | 5 | public class Solution { 6 | public int minOperations(int k) { 7 | int a = (int) Math.sqrt(k); 8 | return a + (k - 1) / a - 1; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/g2701_2800/s2703_return_length_of_arguments_passed/solution.test.ts: -------------------------------------------------------------------------------- 1 | // tslint:disable:no-magic-numbers 2 | import { argumentsLength } from 'src/main/java/g2701_2800/s2703_return_length_of_arguments_passed/solution' 3 | import { expect, test } from 'vitest' 4 | 5 | test('argumentsLength', () => { 6 | expect(argumentsLength(5)).toEqual(1) 7 | }) 8 | 9 | test('argumentsLength2', () => { 10 | expect(argumentsLength({}, null, '3')).toEqual(3) 11 | }) 12 | -------------------------------------------------------------------------------- /src/main/java/g0601_0700/s0602_friend_requests_ii_who_has_the_most_friends/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #Database #2023_06_05_Time_510_ms_(60.15%)_Space_0B_(100.00%) 3 | SELECT req AS id, COUNT(acc) AS num 4 | FROM 5 | ((SELECT requester_id AS req, accepter_id AS acc 6 | FROM requestaccepted) 7 | UNION 8 | (SELECT accepter_id AS req, requester_id AS acc 9 | FROM requestaccepted)) t 10 | GROUP BY req 11 | ORDER BY num DESC 12 | LIMIT 1 13 | -------------------------------------------------------------------------------- /src/main/java/g1201_1300/s1280_students_and_examinations/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2023_08_14_Time_1735_ms_(83.69%)_Space_0B_(100.00%) 3 | SELECT s.student_id, s.student_name, sub.subject_name, 4 | sum(case when sub.subject_name = e.subject_name then 1 else 0 end) as attended_exams 5 | FROM Students s 6 | cross join subjects sub 7 | left join examinations e on e.student_id=s.student_id 8 | group by 1,2,3 9 | order by 1,2,3 10 | -------------------------------------------------------------------------------- /src/main/java/g1901_2000/s1952_three_divisors/Solution.java: -------------------------------------------------------------------------------- 1 | package g1901_2000.s1952_three_divisors; 2 | 3 | // #Easy #Math #2022_05_18_Time_1_ms_(84.91%)_Space_39.4_MB_(79.95%) 4 | 5 | public class Solution { 6 | public boolean isThree(int n) { 7 | int divisors = 0; 8 | for (int i = 1; i <= n; i++) { 9 | if (n % i == 0) { 10 | divisors++; 11 | } 12 | } 13 | return divisors == 3; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g2501_2600/s2527_find_xor_beauty_of_array/Solution.java: -------------------------------------------------------------------------------- 1 | package g2501_2600.s2527_find_xor_beauty_of_array; 2 | 3 | // #Medium #Array #Math #Bit_Manipulation #2023_04_19_Time_1_ms_(100.00%)_Space_59.1_MB_(62.11%) 4 | 5 | public class Solution { 6 | public int xorBeauty(int[] arr) { 7 | int i = 1; 8 | while (i < arr.length) { 9 | arr[0] ^= arr[i]; 10 | i++; 11 | } 12 | return arr[0]; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/g2501_2600/s2545_sort_the_students_by_their_kth_score/Solution.java: -------------------------------------------------------------------------------- 1 | package g2501_2600.s2545_sort_the_students_by_their_kth_score; 2 | 3 | // #Medium #Array #Sorting #Matrix #2023_05_11_Time_1_ms_(99.50%)_Space_53.2_MB_(6.86%) 4 | 5 | import java.util.Arrays; 6 | 7 | public class Solution { 8 | public int[][] sortTheStudents(int[][] score, int k) { 9 | Arrays.sort(score, (o1, o2) -> o2[k] - o1[k]); 10 | return score; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/g0701_0800/s0717_1_bit_and_2_bit_characters/Solution.java: -------------------------------------------------------------------------------- 1 | package g0701_0800.s0717_1_bit_and_2_bit_characters; 2 | 3 | // #Easy #Array #2022_03_24_Time_0_ms_(100.00%)_Space_43.5_MB_(19.69%) 4 | 5 | public class Solution { 6 | public boolean isOneBitCharacter(int[] arr) { 7 | int i = 0; 8 | while (i < arr.length - 1) { 9 | i = (arr[i] == 1) ? i + 2 : i + 1; 10 | } 11 | return (i == arr.length - 1); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/g0701_0800/s0779_k_th_symbol_in_grammar/Solution.java: -------------------------------------------------------------------------------- 1 | package g0701_0800.s0779_k_th_symbol_in_grammar; 2 | 3 | // #Medium #Math #Bit_Manipulation #Recursion #2022_03_26_Time_0_ms_(100.00%)_Space_40.9_MB_(42.87%) 4 | 5 | @SuppressWarnings("java:S1172") 6 | public class Solution { 7 | /* 8 | * Time: O(logn) 9 | * Space: O(1) 10 | */ 11 | public int kthGrammar(int n, int k) { 12 | return Integer.bitCount(k - 1) % 2; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/g1601_1700/s1661_average_time_of_process_per_machine/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2023_08_16_Time_429_ms_(79.06%)_Space_0B_(100.00%) 3 | select act1.machine_id,round(avg(act2.timestamp-act1.timestamp),3) as processing_time from activity act1 join activity act2 on act1.machine_id=act2.machine_id 4 | where act1.process_id = act2.process_id and act1.activity_type ='start' 5 | and act2.activity_type = 'end' group by act1.machine_id; 6 | -------------------------------------------------------------------------------- /src/main/java/g2301_2400/s2358_maximum_number_of_groups_entering_a_competition/Solution.java: -------------------------------------------------------------------------------- 1 | package g2301_2400.s2358_maximum_number_of_groups_entering_a_competition; 2 | 3 | // #Medium #Array #Math #Greedy #Binary_Search 4 | // #2022_08_14_Time_0_ms_(100.00%)_Space_70.5_MB_(27.33%) 5 | 6 | public class Solution { 7 | public int maximumGroups(int[] grades) { 8 | int len = grades.length; 9 | return (int) (-1 + Math.sqrt(1D + 8 * len)) / 2; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/g3101_3200/s3110_score_of_a_string/Solution.java: -------------------------------------------------------------------------------- 1 | package g3101_3200.s3110_score_of_a_string; 2 | 3 | // #Easy #String #2024_04_27_Time_1_ms_(99.93%)_Space_41.4_MB_(99.03%) 4 | 5 | public class Solution { 6 | public int scoreOfString(String s) { 7 | int sum = 0; 8 | for (int i = 0; i < s.length() - 1; i++) { 9 | sum += Math.abs((s.charAt(i) - '0') - (s.charAt(i + 1) - '0')); 10 | } 11 | return sum; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/g0101_0200/s0194_transpose_file/readme.md: -------------------------------------------------------------------------------- 1 | 194\. Transpose File 2 | 3 | Medium 4 | 5 | Given a text file `file.txt`, transpose its content. 6 | 7 | You may assume that each row has the same number of columns, and each field is separated by the `' '` character. 8 | 9 | **Example:** 10 | 11 | If `file.txt` has the following content: 12 | 13 | name age 14 | alice 21 15 | ryan 30 16 | 17 | Output the following: 18 | 19 | name alice ryan 20 | age 21 30 -------------------------------------------------------------------------------- /src/main/java/g0301_0400/s0342_power_of_four/Solution.java: -------------------------------------------------------------------------------- 1 | package g0301_0400.s0342_power_of_four; 2 | 3 | // #Easy #Math #Bit_Manipulation #Recursion #2022_07_10_Time_1_ms_(100.00%)_Space_41.2_MB_(55.90%) 4 | 5 | public class Solution { 6 | public boolean isPowerOfFour(int n) { 7 | while (n >= 4) { 8 | if (n % 4 != 0) { 9 | return false; 10 | } 11 | n = n / 4; 12 | } 13 | return n == 1; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g1201_1300/s1227_airplane_seat_assignment_probability/Solution.java: -------------------------------------------------------------------------------- 1 | package g1201_1300.s1227_airplane_seat_assignment_probability; 2 | 3 | // #Medium #Dynamic_Programming #Math #Brainteaser #Probability_and_Statistics 4 | // #2022_03_12_Time_1_ms_(15.63%)_Space_41.7_MB_(12.95%) 5 | 6 | public class Solution { 7 | public double nthPersonGetsNthSeat(int n) { 8 | if (n == 1) { 9 | return 1.0D; 10 | } 11 | return 0.5D; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/g1701_1800/s1731_the_number_of_employees_which_report_to_each_employee/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2023_08_16_Time_1162_ms_(87.26%)_Space_0B_(100.00%) 3 | SELECT 4 | t1.employee_id, 5 | t1.name, 6 | count(t2.reports_to) as reports_count, 7 | ROUND(avg(t2.age)) as average_age 8 | FROM 9 | Employees t1 10 | INNER JOIN Employees t2 on t1.employee_id = t2.reports_to 11 | GROUP BY 1, 2 12 | ORDER BY employee_id 13 | -------------------------------------------------------------------------------- /src/main/java/g1901_2000/s1920_build_array_from_permutation/Solution.java: -------------------------------------------------------------------------------- 1 | package g1901_2000.s1920_build_array_from_permutation; 2 | 3 | // #Easy #Array #Simulation #2022_05_14_Time_1_ms_(94.23%)_Space_54.1_MB_(13.18%) 4 | 5 | public class Solution { 6 | public int[] buildArray(int[] nums) { 7 | int[] ans = new int[nums.length]; 8 | for (int i = 0; i < nums.length; i++) { 9 | ans[i] = nums[nums[i]]; 10 | } 11 | return ans; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/g2001_2100/s2057_smallest_index_with_equal_value/Solution.java: -------------------------------------------------------------------------------- 1 | package g2001_2100.s2057_smallest_index_with_equal_value; 2 | 3 | // #Easy #Array #2022_05_26_Time_1_ms_(94.39%)_Space_46.9_MB_(19.23%) 4 | 5 | public class Solution { 6 | public int smallestEqual(int[] nums) { 7 | for (int i = 0; i < nums.length; i++) { 8 | if (i % 10 == nums[i]) { 9 | return i; 10 | } 11 | } 12 | return -1; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/g2501_2600/s2582_pass_the_pillow/Solution.java: -------------------------------------------------------------------------------- 1 | package g2501_2600.s2582_pass_the_pillow; 2 | 3 | // #Easy #Math #Simulation #2023_08_22_Time_0_ms_(100.00%)_Space_39.3_MB_(46.65%) 4 | 5 | public class Solution { 6 | public int passThePillow(int n, int time) { 7 | int roundTrip = (n - 1) * 2; 8 | time = time % roundTrip; 9 | if (time < n) { 10 | return time + 1; 11 | } 12 | return n - (time - n + 1); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/g3401_3500/s3498_reverse_degree_of_a_string/Solution.java: -------------------------------------------------------------------------------- 1 | package g3401_3500.s3498_reverse_degree_of_a_string; 2 | 3 | // #Easy #String #Simulation #2025_04_01_Time_1_ms_(100.00%)_Space_42.64_MB_(92.21%) 4 | 5 | public class Solution { 6 | public int reverseDegree(String s) { 7 | int ans = 0; 8 | for (int i = 0; i < s.length(); ++i) { 9 | ans += (26 - (s.charAt(i) - 'a')) * (i + 1); 10 | } 11 | return ans; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/g0101_0200/s0194_transpose_file/script.sh: -------------------------------------------------------------------------------- 1 | # Read from the file file.txt and print its transposed content to stdout. 2 | # #Medium #Shell #2025_05_03_Time_61_ms_(88.19%)_Space_4.14_MB_(38.67%) 3 | awk ' 4 | { 5 | for (i = 1; i <= NF; i++) { 6 | if (NR == 1) { 7 | a[i] = $i 8 | } else { 9 | a[i] = a[i] " " $i 10 | } 11 | } 12 | } 13 | END { 14 | for (i = 1; i <= NF; i++) { 15 | print a[i] 16 | } 17 | }' file.txt 18 | -------------------------------------------------------------------------------- /src/main/java/g3501_3600/s3512_minimum_operations_to_make_array_sum_divisible_by_k/Solution.java: -------------------------------------------------------------------------------- 1 | package g3501_3600.s3512_minimum_operations_to_make_array_sum_divisible_by_k; 2 | 3 | // #Easy #Array #Math #2025_04_14_Time_1_ms_(100.00%)_Space_45.24_MB_(100.00%) 4 | 5 | public class Solution { 6 | public int minOperations(int[] nums, int k) { 7 | int sum = 0; 8 | for (int num : nums) { 9 | sum += num; 10 | } 11 | return sum % k; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/g0801_0900/s0810_chalkboard_xor_game/Solution.java: -------------------------------------------------------------------------------- 1 | package g0801_0900.s0810_chalkboard_xor_game; 2 | 3 | // #Hard #Array #Math #Bit_Manipulation #Game_Theory #Brainteaser 4 | // #2022_03_23_Time_0_ms_(100.00%)_Space_41.6_MB_(95.74%) 5 | 6 | public class Solution { 7 | public boolean xorGame(int[] nums) { 8 | int xor = 0; 9 | for (int i : nums) { 10 | xor = xor ^ i; 11 | } 12 | return xor == 0 || (nums.length & 1) == 0; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/g2601_2700/s2677_chunk_array/solution.ts: -------------------------------------------------------------------------------- 1 | // #Easy #2023_09_11_Time_49_ms_(96.15%)_Space_44.4_MB_(96.63%) 2 | 3 | function chunk(arr: any[], size: number): any[][] { 4 | if (arr.length === 0) return [] 5 | if (size >= arr.length) return [arr] 6 | let i: number = 0 7 | let res: Array> = [] 8 | while (i < arr.length) { 9 | res.push(arr.slice(i, i + size)) 10 | i += size 11 | } 12 | return res 13 | } 14 | 15 | export { chunk } 16 | -------------------------------------------------------------------------------- /src/main/java/g1901_2000/s1907_count_salary_categories/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #Database #2023_08_17_Time_2216_ms_(95.81%)_Space_0B_(100.00%) 3 | select 'Low Salary' as category, count(*) as accounts_count from accounts where income<20000 4 | union 5 | select 'Average Salary' as category, count(*) as accounts_count from accounts where income>=20000 and income<=50000 6 | union 7 | select 'High Salary' as category, count(*) as accounts_count from accounts where income>50000 8 | -------------------------------------------------------------------------------- /src/main/java/g1101_1200/s1174_immediate_food_delivery_ii/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #Database #2023_08_12_Time_1205_ms_(78.39%)_Space_0B_(100.00%) 3 | SELECT ROUND(AVG(CASE WHEN customer_pref_delivery_date = order_date THEN 1 ELSE 0 END) * 100, 2) AS immediate_percentage 4 | FROM ( 5 | SELECT *, 6 | DENSE_RANK() OVER(PARTITION BY customer_id ORDER BY order_date ASC) AS dnsrnk 7 | FROM delivery 8 | ) subquery_alias 9 | WHERE subquery_alias.dnsrnk = 1; 10 | -------------------------------------------------------------------------------- /src/main/java/g3601_3700/s3648_minimum_sensors_to_cover_grid/Solution.java: -------------------------------------------------------------------------------- 1 | package g3601_3700.s3648_minimum_sensors_to_cover_grid; 2 | 3 | // #Medium #Math #Biweekly_Contest_163 #2025_09_26_Time_0_ms_(100.00%)_Space_41.09_MB_(54.77%) 4 | 5 | public class Solution { 6 | public int minSensors(int n, int m, int k) { 7 | int size = k * 2 + 1; 8 | int x = n / size + (n % size == 0 ? 0 : 1); 9 | int y = m / size + (m % size == 0 ? 0 : 1); 10 | return x * y; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/g0001_0100/s0069_sqrtx/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0001_0100.s0069_sqrtx; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void mySqrt() { 11 | assertThat(new Solution().mySqrt(4), equalTo(2)); 12 | } 13 | 14 | @Test 15 | void mySqrt2() { 16 | assertThat(new Solution().mySqrt(8), equalTo(2)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g1001_1100/s1095_find_in_mountain_array/MountainArrayImpl.java: -------------------------------------------------------------------------------- 1 | package g1001_1100.s1095_find_in_mountain_array; 2 | 3 | class MountainArrayImpl implements MountainArray { 4 | private int[] ints; 5 | 6 | public MountainArrayImpl(int[] ints) { 7 | this.ints = ints; 8 | } 9 | 10 | @Override 11 | public int get(int index) { 12 | return ints[index]; 13 | } 14 | 15 | @Override 16 | public int length() { 17 | return ints.length; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/g0201_0300/s0268_missing_number/Solution.java: -------------------------------------------------------------------------------- 1 | package g0201_0300.s0268_missing_number; 2 | 3 | // #Easy #Array #Hash_Table #Math #Sorting #Binary_Search #Bit_Manipulation 4 | // #2022_07_05_Time_1_ms_(72.07%)_Space_50.6_MB_(76.88%) 5 | 6 | public class Solution { 7 | public int missingNumber(int[] nums) { 8 | int a = nums.length; 9 | for (int i = 0; i < nums.length; i++) { 10 | a ^= i; 11 | a ^= nums[i]; 12 | } 13 | return a; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g0501_0600/s0507_perfect_number/Solution.java: -------------------------------------------------------------------------------- 1 | package g0501_0600.s0507_perfect_number; 2 | 3 | // #Easy #Math #2022_07_24_Time_2_ms_(80.46%)_Space_41.5_MB_(9.33%) 4 | 5 | public class Solution { 6 | public boolean checkPerfectNumber(int num) { 7 | int s = 1; 8 | for (int sq = (int) Math.sqrt(num); sq > 1; sq--) { 9 | if (num % sq == 0) { 10 | s += sq + (num / sq); 11 | } 12 | } 13 | return num != 1 && s == num; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g1301_1400/s1321_restaurant_growth/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #Database #2023_08_14_Time_775_ms_(61.73%)_Space_0B_(100.00%) 3 | with cteX as 4 | (select visited_on, sum(amount) as amount from customer 5 | group by visited_on) 6 | 7 | SELECT visited_on, SUM(amount) OVER(ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS amount, 8 | round(AVG(amount) OVER(ROWS BETWEEN 6 PRECEDING AND CURRENT ROW), 2) as average_amount FROM cteX 9 | order by visited_on 10 | limit 6, 10000 11 | -------------------------------------------------------------------------------- /src/main/java/g2101_2200/s2177_find_three_consecutive_integers_that_sum_to_a_given_number/Solution.java: -------------------------------------------------------------------------------- 1 | package g2101_2200.s2177_find_three_consecutive_integers_that_sum_to_a_given_number; 2 | 3 | // #Medium #Math #Simulation #2022_06_06_Time_1_ms_(78.46%)_Space_42_MB_(56.19%) 4 | 5 | public class Solution { 6 | public long[] sumOfThree(long num) { 7 | if (num % 3 == 0) { 8 | return new long[] {num / 3 - 1, num / 3, num / 3 + 1}; 9 | } 10 | return new long[0]; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/g0701_0800/s0745_prefix_and_suffix_search/WordFilterTest.java: -------------------------------------------------------------------------------- 1 | package g0701_0800.s0745_prefix_and_suffix_search; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class WordFilterTest { 9 | @Test 10 | void wordFilterTest() { 11 | WordFilter wordFilter = new WordFilter(new String[] {"apple"}); 12 | assertThat(wordFilter.f("a", "e"), equalTo(0)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | | Version | Supported | 6 | |---------|--------------------| 7 | | >= 1.2 | :white_check_mark: | 8 | | < 1.2 | :x: | 9 | 10 | ## Reporting a Vulnerability 11 | 12 | In case you have found a vulnerability, please open a public issue in the repository. This will help developers to address the problem and solve. 13 | 14 | If you have evidence of a zero-day exploit, please directly contact to project owner with exploit details. 15 | -------------------------------------------------------------------------------- /src/main/java/g0001_0100/s0059_spiral_matrix_ii/readme.md: -------------------------------------------------------------------------------- 1 | 59\. Spiral Matrix II 2 | 3 | Medium 4 | 5 | Given a positive integer `n`, generate an `n x n` `matrix` filled with elements from `1` to `n2` in spiral order. 6 | 7 | **Example 1:** 8 | 9 | ![](https://assets.leetcode.com/uploads/2020/11/13/spiraln.jpg) 10 | 11 | **Input:** n = 3 12 | 13 | **Output:** [[1,2,3],[8,9,4],[7,6,5]] 14 | 15 | **Example 2:** 16 | 17 | **Input:** n = 1 18 | 19 | **Output:** [[1]] 20 | 21 | **Constraints:** 22 | 23 | * `1 <= n <= 20` -------------------------------------------------------------------------------- /src/main/java/g1301_1400/s1327_list_the_products_ordered_in_a_period/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2023_08_16_Time_1374_ms_(80.18%)_Space_0B_(100.00%) 3 | SELECT * FROM ( 4 | SELECT 5 | a.product_name, 6 | SUM(b.unit) as unit 7 | FROM Products a 8 | LEFT JOIN Orders b 9 | ON a.product_id = b.product_id 10 | WHERE b.order_date BETWEEN '2020-02-01' AND '2020-02-29' 11 | GROUP BY a.product_name 12 | ) AS d 13 | GROUP BY d.product_name 14 | HAVING d.unit >= 100 15 | -------------------------------------------------------------------------------- /src/main/java/g1501_1600/s1523_count_odd_numbers_in_an_interval_range/Solution.java: -------------------------------------------------------------------------------- 1 | package g1501_1600.s1523_count_odd_numbers_in_an_interval_range; 2 | 3 | // #Easy #Math #Programming_Skills_I_Day_1_Basic_Data_Type 4 | // #2022_04_09_Time_0_ms_(100.00%)_Space_41.5_MB_(10.62%) 5 | 6 | public class Solution { 7 | public int countOdds(int low, int high) { 8 | if (low % 2 != 0 || high % 2 != 0) { 9 | return (high - low) / 2 + 1; 10 | } 11 | return (high - low) / 2; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/g1901_2000/s1913_maximum_product_difference_between_two_pairs/Solution.java: -------------------------------------------------------------------------------- 1 | package g1901_2000.s1913_maximum_product_difference_between_two_pairs; 2 | 3 | // #Easy #Array #Sorting #2022_05_24_Time_7_ms_(70.01%)_Space_42.6_MB_(82.74%) 4 | 5 | import java.util.Arrays; 6 | 7 | public class Solution { 8 | public int maxProductDifference(int[] nums) { 9 | Arrays.sort(nums); 10 | int len = nums.length; 11 | return nums[len - 1] * nums[len - 2] - nums[0] * nums[1]; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/g2701_2800/s2739_total_distance_traveled/Solution.java: -------------------------------------------------------------------------------- 1 | package g2701_2800.s2739_total_distance_traveled; 2 | 3 | // #Easy #Math #Simulation #2023_09_23_Time_4_ms_(100.00%)_Space_43.3_MB_(10.42%) 4 | 5 | public class Solution { 6 | public int distanceTraveled(int mainTank, int additionalTank) { 7 | int transferableTimes = (mainTank - 1) / 4; 8 | int transferredLiters = Math.min(transferableTimes, additionalTank); 9 | return (mainTank + transferredLiters) * 10; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/test/java/g0801_0900/s0818_race_car/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0801_0900.s0818_race_car; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void raceCar() { 11 | assertThat(new Solution().racecar(3), equalTo(2)); 12 | } 13 | 14 | @Test 15 | void raceCar2() { 16 | assertThat(new Solution().racecar(6), equalTo(5)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g2601_2700/s2621_sleep/solution.test.ts: -------------------------------------------------------------------------------- 1 | // tslint:disable:no-magic-numbers 2 | import { sleep } from 'src/main/java/g2601_2700/s2621_sleep/solution' 3 | import { expect, test } from 'vitest' 4 | 5 | test('sleep', () => { 6 | let t = Date.now() 7 | sleep(100).then(() => { 8 | expect(Date.now() - t).toEqual(100) 9 | }) 10 | }) 11 | 12 | test('sleep2', () => { 13 | let t = Date.now() 14 | sleep(200).then(() => { 15 | expect(Date.now() - t).toEqual(200) 16 | }) 17 | }) 18 | -------------------------------------------------------------------------------- /src/test/java/g2701_2800/s2726_calculator_with_method_chaining/solution.test.ts: -------------------------------------------------------------------------------- 1 | import { Calculator } from 'src/main/java/g2701_2800/s2726_calculator_with_method_chaining/solution' 2 | import { expect, test } from 'vitest' 3 | 4 | test('calculator', () => { 5 | const result = new Calculator(10).add(5).subtract(7).getResult() 6 | expect(result).toEqual(8) 7 | }) 8 | 9 | test('calculator2', () => { 10 | const result = new Calculator(2).multiply(5).power(2).getResult() 11 | expect(result).toEqual(100) 12 | }) 13 | -------------------------------------------------------------------------------- /src/main/java/g0601_0700/s0657_robot_return_to_origin/Solution.java: -------------------------------------------------------------------------------- 1 | package g0601_0700.s0657_robot_return_to_origin; 2 | 3 | // #Easy #String #Simulation #2022_03_21_Time_3_ms_(99.87%)_Space_45.2_MB_(25.61%) 4 | 5 | public class Solution { 6 | public boolean judgeCircle(String moves) { 7 | int[] map = new int[26]; 8 | for (char c : moves.toCharArray()) { 9 | map[c - 'A']++; 10 | } 11 | return map['U' - 'A'] == map['D' - 'A'] && map['L' - 'A'] == map['R' - 'A']; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/g0901_1000/s0912_sort_an_array/readme.md: -------------------------------------------------------------------------------- 1 | 912\. Sort an Array 2 | 3 | Medium 4 | 5 | Given an array of integers `nums`, sort the array in ascending order. 6 | 7 | **Example 1:** 8 | 9 | **Input:** nums = [5,2,3,1] 10 | 11 | **Output:** [1,2,3,5] 12 | 13 | **Example 2:** 14 | 15 | **Input:** nums = [5,1,1,2,0,0] 16 | 17 | **Output:** [0,0,1,1,2,5] 18 | 19 | **Constraints:** 20 | 21 | * 1 <= nums.length <= 5 * 104 22 | * -5 * 104 <= nums[i] <= 5 * 104 -------------------------------------------------------------------------------- /src/main/java/g1701_1800/s1789_primary_department_for_each_employee/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #2023_08_16_Time_1122_ms_(74.47%)_Space_0B_(100.00%) 3 | WITH cte AS ( 4 | SELECT DISTINCT employee_id, department_id, 5 | COUNT(employee_id) OVER (PARTITION BY employee_id) AS n 6 | FROM Employee 7 | ) 8 | SELECT employee_id, department_id 9 | FROM cte 10 | WHERE n = 1 11 | UNION 12 | SELECT employee_id, department_id 13 | FROM Employee 14 | WHERE primary_flag = 'Y'; 15 | -------------------------------------------------------------------------------- /src/main/java/g1801_1900/s1837_sum_of_digits_in_base_k/Solution.java: -------------------------------------------------------------------------------- 1 | package g1801_1900.s1837_sum_of_digits_in_base_k; 2 | 3 | // #Easy #Math #2025_02_23_Time_0_ms_(100.00%)_Space_40.80_MB_(21.87%) 4 | 5 | public class Solution { 6 | public int sumBase(int n, int k) { 7 | int a; 8 | int sum = 0; 9 | int b; 10 | while (n != 0) { 11 | a = n % k; 12 | b = n / k; 13 | sum += a; 14 | n = b; 15 | } 16 | return sum; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/g3001_3100/s3046_split_the_array/Solution.java: -------------------------------------------------------------------------------- 1 | package g3001_3100.s3046_split_the_array; 2 | 3 | // #Easy #Array #Hash_Table #Counting #2024_02_29_Time_1_ms_(98.82%)_Space_42.8_MB_(63.55%) 4 | 5 | public class Solution { 6 | public boolean isPossibleToSplit(int[] nums) { 7 | int[] a = new int[101]; 8 | for (int n : nums) { 9 | a[n]++; 10 | if (a[n] > 2) { 11 | return false; 12 | } 13 | } 14 | return true; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/g0301_0400/s0367_valid_perfect_square/readme.md: -------------------------------------------------------------------------------- 1 | 367\. Valid Perfect Square 2 | 3 | Easy 4 | 5 | Given a **positive** integer _num_, write a function which returns True if _num_ is a perfect square else False. 6 | 7 | **Follow up:** **Do not** use any built-in library function such as `sqrt`. 8 | 9 | **Example 1:** 10 | 11 | **Input:** num = 16 12 | 13 | **Output:** true 14 | 15 | **Example 2:** 16 | 17 | **Input:** num = 14 18 | 19 | **Output:** false 20 | 21 | **Constraints:** 22 | 23 | * `1 <= num <= 2^31 - 1` -------------------------------------------------------------------------------- /src/main/java/g0401_0500/s0430_flatten_a_multilevel_doubly_linked_list/Node.java: -------------------------------------------------------------------------------- 1 | package g0401_0500.s0430_flatten_a_multilevel_doubly_linked_list; 2 | 3 | @SuppressWarnings("java:S1104") 4 | public class Node { 5 | public int val; 6 | public Node prev; 7 | public Node next; 8 | public Node child; 9 | 10 | public Node(int val) { 11 | this.val = val; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return "Node{" + "val=" + val + ",next=" + next + "}"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/g1501_1600/s1550_three_consecutive_odds/Solution.java: -------------------------------------------------------------------------------- 1 | package g1501_1600.s1550_three_consecutive_odds; 2 | 3 | // #Easy #Array #2022_04_11_Time_0_ms_(100.00%)_Space_43.3_MB_(21.06%) 4 | 5 | public class Solution { 6 | public boolean threeConsecutiveOdds(int[] arr) { 7 | for (int i = 0; i < arr.length - 2; i++) { 8 | if (arr[i] % 2 == 1 && arr[i + 1] % 2 == 1 && arr[i + 2] % 2 == 1) { 9 | return true; 10 | } 11 | } 12 | return false; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/g1701_1800/s1720_decode_xored_array/Solution.java: -------------------------------------------------------------------------------- 1 | package g1701_1800.s1720_decode_xored_array; 2 | 3 | // #Easy #Array #Bit_Manipulation #2022_04_24_Time_1_ms_(100.00%)_Space_57.3_MB_(6.33%) 4 | 5 | public class Solution { 6 | public int[] decode(int[] encoded, int first) { 7 | int[] arr = new int[encoded.length + 1]; 8 | arr[0] = first; 9 | for (int i = 0; i < encoded.length; i++) { 10 | arr[i + 1] = encoded[i] ^ arr[i]; 11 | } 12 | return arr; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/g2101_2200/s2185_counting_words_with_a_given_prefix/Solution.java: -------------------------------------------------------------------------------- 1 | package g2101_2200.s2185_counting_words_with_a_given_prefix; 2 | 3 | // #Easy #Array #String #2022_06_08_Time_0_ms_(100.00%)_Space_43.9_MB_(15.40%) 4 | 5 | public class Solution { 6 | public int prefixCount(String[] words, String pref) { 7 | int count = 0; 8 | for (String s : words) { 9 | if (s.startsWith(pref)) { 10 | count++; 11 | } 12 | } 13 | return count; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g2201_2300/s2255_count_prefixes_of_a_given_string/Solution.java: -------------------------------------------------------------------------------- 1 | package g2201_2300.s2255_count_prefixes_of_a_given_string; 2 | 3 | // #Easy #Array #String #2022_06_12_Time_1_ms_(94.82%)_Space_44.1_MB_(51.71%) 4 | 5 | public class Solution { 6 | public int countPrefixes(String[] words, String s) { 7 | int count = 0; 8 | for (String str : words) { 9 | if (s.indexOf(str) == 0) { 10 | ++count; 11 | } 12 | } 13 | return count; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g2701_2800/s2710_remove_trailing_zeros_from_a_string/Solution.java: -------------------------------------------------------------------------------- 1 | package g2701_2800.s2710_remove_trailing_zeros_from_a_string; 2 | 3 | // #Easy #String #2023_09_15_Time_1_ms_(100.00%)_Space_43.5_MB_(80.00%) 4 | 5 | public class Solution { 6 | public String removeTrailingZeros(String num) { 7 | int endIndex = num.length() - 1; 8 | while (endIndex >= 0 && num.charAt(endIndex) == '0') { 9 | endIndex--; 10 | } 11 | return num.substring(0, endIndex + 1); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/g0201_0300/s0258_add_digits/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0201_0300.s0258_add_digits; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void addDigits() { 11 | assertThat(new Solution().addDigits(38), equalTo(2)); 12 | } 13 | 14 | @Test 15 | void addDigits2() { 16 | assertThat(new Solution().addDigits(0), equalTo(0)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g2201_2300/s2235_add_two_integers/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g2201_2300.s2235_add_two_integers; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void sum() { 11 | assertThat(new Solution().sum(12, 5), equalTo(17)); 12 | } 13 | 14 | @Test 15 | void sum2() { 16 | assertThat(new Solution().sum(-10, 4), equalTo(-6)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/g0601_0700/s0633_sum_of_square_numbers/readme.md: -------------------------------------------------------------------------------- 1 | 633\. Sum of Square Numbers 2 | 3 | Medium 4 | 5 | Given a non-negative integer `c`, decide whether there're two integers `a` and `b` such that a2 + b2 = c. 6 | 7 | **Example 1:** 8 | 9 | **Input:** c = 5 10 | 11 | **Output:** true 12 | 13 | **Explanation:** 1 \* 1 + 2 \* 2 = 5 14 | 15 | **Example 2:** 16 | 17 | **Input:** c = 3 18 | 19 | **Output:** false 20 | 21 | **Constraints:** 22 | 23 | * 0 <= c <= 231 - 1 -------------------------------------------------------------------------------- /src/main/java/g1301_1400/s1332_remove_palindromic_subsequences/Solution.java: -------------------------------------------------------------------------------- 1 | package g1301_1400.s1332_remove_palindromic_subsequences; 2 | 3 | // #Easy #String #Two_Pointers #2022_03_19_Time_0_ms_(100.00%)_Space_39.9_MB_(78.40%) 4 | 5 | public class Solution { 6 | public int removePalindromeSub(String s) { 7 | if (s.isEmpty()) { 8 | return 0; 9 | } 10 | if (s.equals((new StringBuilder(s)).reverse().toString())) { 11 | return 1; 12 | } 13 | return 2; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g2401_2500/s2427_number_of_common_factors/Solution.java: -------------------------------------------------------------------------------- 1 | package g2401_2500.s2427_number_of_common_factors; 2 | 3 | // #Easy #Math #Enumeration #Number_Theory #2022_12_07_Time_1_ms_(81.93%)_Space_38.7_MB_(98.17%) 4 | 5 | public class Solution { 6 | public int commonFactors(int a, int b) { 7 | int ans = 0; 8 | for (int i = 1; i <= Math.min(a, b); i++) { 9 | if (a % i == 0 && b % i == 0) { 10 | ans++; 11 | } 12 | } 13 | return ans; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g2401_2500/s2469_convert_the_temperature/Solution.java: -------------------------------------------------------------------------------- 1 | package g2401_2500.s2469_convert_the_temperature; 2 | 3 | // #Easy #Math #2023_01_11_Time_0_ms_(100.00%)_Space_40.6_MB_(87.87%) 4 | 5 | public class Solution { 6 | public double[] convertTemperature(double celsius) { 7 | double kelvin = celsius + 273.15; 8 | double fahrenheit = celsius * 1.80 + 32.00; 9 | double[] arr = new double[2]; 10 | arr[0] = kelvin; 11 | arr[1] = fahrenheit; 12 | return arr; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/g3601_3700/s3674_minimum_operations_to_equalize_array/Solution.java: -------------------------------------------------------------------------------- 1 | package g3601_3700.s3674_minimum_operations_to_equalize_array; 2 | 3 | // #Easy #Array #Bit_Manipulation #Brainteaser #Weekly_Contest_466 4 | // #2025_09_26_Time_0_ms_(100.00%)_Space_43.29_MB_(90.84%) 5 | 6 | public class Solution { 7 | public int minOperations(int[] nums) { 8 | for (int num : nums) { 9 | if (num != nums[0]) { 10 | return 1; 11 | } 12 | } 13 | return 0; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/g0201_0300/s0202_happy_number/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0201_0300.s0202_happy_number; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void isHappy() { 11 | assertThat(new Solution().isHappy(19), equalTo(true)); 12 | } 13 | 14 | @Test 15 | void isHappy2() { 16 | assertThat(new Solution().isHappy(2), equalTo(false)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0601_0700/s0650_2_keys_keyboard/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0601_0700.s0650_2_keys_keyboard; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void minSteps() { 11 | assertThat(new Solution().minSteps(3), equalTo(3)); 12 | } 13 | 14 | @Test 15 | void minSteps2() { 16 | assertThat(new Solution().minSteps(1), equalTo(0)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g1001_1100/s1006_clumsy_factorial/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g1001_1100.s1006_clumsy_factorial; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void clumsy() { 11 | assertThat(new Solution().clumsy(4), equalTo(7)); 12 | } 13 | 14 | @Test 15 | void clumsy2() { 16 | assertThat(new Solution().clumsy(10), equalTo(12)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/g1101_1200/s1164_product_price_at_a_given_date/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #Database #2023_08_12_Time_920_ms_(76.39%)_Space_0B_(100.00%) 3 | WITH cte AS 4 | (SELECT *, RANK() OVER (PARTITION BY product_id ORDER BY change_date DESC) AS r 5 | FROM Products 6 | WHERE change_date<= '2019-08-16') 7 | 8 | SELECT product_id, new_price AS price 9 | FROM cte 10 | WHERE r = 1 11 | UNION 12 | SELECT product_id, 10 AS price 13 | FROM Products 14 | WHERE product_id NOT IN (SELECT product_id FROM cte) 15 | -------------------------------------------------------------------------------- /src/main/java/g3001_3100/s3065_minimum_operations_to_exceed_threshold_value_i/Solution.java: -------------------------------------------------------------------------------- 1 | package g3001_3100.s3065_minimum_operations_to_exceed_threshold_value_i; 2 | 3 | // #Easy #Array #2024_03_31_Time_0_ms_(100.00%)_Space_42.7_MB_(48.42%) 4 | 5 | public class Solution { 6 | public int minOperations(int[] nums, int k) { 7 | int count = 0; 8 | for (int num : nums) { 9 | if (num >= k) { 10 | count++; 11 | } 12 | } 13 | return nums.length - count; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g3201_3300/s3222_find_the_winning_player_in_coin_game/Solution.java: -------------------------------------------------------------------------------- 1 | package g3201_3300.s3222_find_the_winning_player_in_coin_game; 2 | 3 | // #Easy #Math #Simulation #Game_Theory #2024_07_23_Time_0_ms_(100.00%)_Space_41.6_MB_(67.81%) 4 | 5 | public class Solution { 6 | public String losingPlayer(int x, int y) { 7 | boolean w = false; 8 | while (x > 0 && y >= 4) { 9 | x--; 10 | y -= 4; 11 | w = !w; 12 | } 13 | return w ? "Alice" : "Bob"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g3201_3300/s3274_check_if_two_chessboard_squares_have_the_same_color/Solution.java: -------------------------------------------------------------------------------- 1 | package g3201_3300.s3274_check_if_two_chessboard_squares_have_the_same_color; 2 | 3 | // #Easy #String #Math #2024_09_02_Time_0_ms_(100.00%)_Space_41.8_MB_(100.00%) 4 | 5 | public class Solution { 6 | public boolean checkTwoChessboards(String c1, String c2) { 7 | int s1 = (c1.charAt(0) - 'a') + (c1.charAt(1) - '0'); 8 | int s2 = (c2.charAt(0) - 'a') + (c2.charAt(1) - '0'); 9 | return s1 % 2 == s2 % 2; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/g3501_3600/s3516_find_closest_person/Solution.java: -------------------------------------------------------------------------------- 1 | package g3501_3600.s3516_find_closest_person; 2 | 3 | // #Easy #Math #2025_04_14_Time_0_ms_(100.00%)_Space_41.20_MB_(_%) 4 | 5 | public class Solution { 6 | public int findClosest(int x, int y, int z) { 7 | int d1 = Math.abs(z - x); 8 | int d2 = Math.abs(z - y); 9 | if (d1 == d2) { 10 | return 0; 11 | } else if (d1 < d2) { 12 | return 1; 13 | } else { 14 | return 2; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/g0101_0200/s0135_candy/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0101_0200.s0135_candy; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void candy() { 11 | assertThat(new Solution().candy(new int[] {1, 0, 2}), equalTo(5)); 12 | } 13 | 14 | @Test 15 | void candy2() { 16 | assertThat(new Solution().candy(new int[] {1, 2, 2}), equalTo(4)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0301_0400/s0319_bulb_switcher/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0301_0400.s0319_bulb_switcher; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void bulbSwitch() { 11 | assertThat(new Solution().bulbSwitch(1), equalTo(1)); 12 | } 13 | 14 | @Test 15 | void bulbSwitch2() { 16 | assertThat(new Solution().bulbSwitch(4), equalTo(2)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0301_0400/s0400_nth_digit/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0301_0400.s0400_nth_digit; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void findNthDigit() { 11 | assertThat(new Solution().findNthDigit(3), equalTo(3)); 12 | } 13 | 14 | @Test 15 | void findNthDigit2() { 16 | assertThat(new Solution().findNthDigit(11), equalTo(0)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g1901_2000/s1952_three_divisors/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g1901_2000.s1952_three_divisors; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void isThree() { 11 | assertThat(new Solution().isThree(2), equalTo(false)); 12 | } 13 | 14 | @Test 15 | void isThree2() { 16 | assertThat(new Solution().isThree(4), equalTo(true)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g3101_3200/s3133_minimum_array_end/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g3101_3200.s3133_minimum_array_end; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void minEnd() { 11 | assertThat(new Solution().minEnd(3, 4), equalTo(6L)); 12 | } 13 | 14 | @Test 15 | void minEnd2() { 16 | assertThat(new Solution().minEnd(2, 7), equalTo(15L)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/g0101_0200/s0171_excel_sheet_column_number/Solution.java: -------------------------------------------------------------------------------- 1 | package g0101_0200.s0171_excel_sheet_column_number; 2 | 3 | // #Easy #Top_Interview_Questions #String #Math #2022_06_26_Time_2_ms_(76.43%)_Space_43_MB_(34.53%) 4 | 5 | public class Solution { 6 | public int titleToNumber(String s) { 7 | int num = 0; 8 | int pow = 0; 9 | for (int i = s.length() - 1; i >= 0; i--) { 10 | num += (int) Math.pow(26, pow++) * (s.charAt(i) - 'A' + 1); 11 | } 12 | return num; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/g0801_0900/s0852_peak_index_in_a_mountain_array/Solution.java: -------------------------------------------------------------------------------- 1 | package g0801_0900.s0852_peak_index_in_a_mountain_array; 2 | 3 | // #Medium #Array #Binary_Search #Binary_Search_I_Day_2 4 | // #2022_03_28_Time_0_ms_(100.00%)_Space_46.1_MB_(68.36%) 5 | 6 | public class Solution { 7 | public int peakIndexInMountainArray(int[] arr) { 8 | for (int i = 1; i < arr.length - 1; i++) { 9 | if (arr[i] > arr[i + 1]) { 10 | return i; 11 | } 12 | } 13 | return -1; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g1701_1800/s1795_rearrange_products_table/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Easy #Database #SQL_I_Day_4_Union_and_Select #2022_04_25_Time_497_ms_(64.83%)_Space_0B_(100.00%) 3 | SELECT product_id, 'store1' AS store, store1 AS price 4 | FROM Products 5 | WHERE store1 IS NOT NULL 6 | UNION 7 | SELECT product_id, 'store2' AS store, store2 AS price 8 | FROM Products 9 | WHERE store2 IS NOT NULL 10 | UNION 11 | SELECT product_id, 'store3' AS store, store3 AS price 12 | FROM Products 13 | WHERE store3 IS NOT NULL; 14 | -------------------------------------------------------------------------------- /src/main/java/g3001_3100/s3028_ant_on_the_boundary/Solution.java: -------------------------------------------------------------------------------- 1 | package g3001_3100.s3028_ant_on_the_boundary; 2 | 3 | // #Easy #Array #Simulation #Prefix_Sum #2024_03_01_Time_0_ms_(100.00%)_Space_42.1_MB_(53.10%) 4 | 5 | public class Solution { 6 | public int returnToBoundaryCount(int[] nums) { 7 | int ans = 0; 8 | int num = 0; 9 | for (int n : nums) { 10 | num += n; 11 | if (num == 0) { 12 | ans++; 13 | } 14 | } 15 | return ans; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/g3301_3400/s3340_check_balanced_string/Solution.java: -------------------------------------------------------------------------------- 1 | package g3301_3400.s3340_check_balanced_string; 2 | 3 | // #Easy #String #2024_11_05_Time_1_ms_(99.60%)_Space_42_MB_(79.77%) 4 | 5 | public class Solution { 6 | public boolean isBalanced(String num) { 7 | int diff = 0; 8 | int sign = 1; 9 | int n = num.length(); 10 | for (int i = 0; i < n; ++i) { 11 | diff += sign * (num.charAt(i) - '0'); 12 | sign = -sign; 13 | } 14 | return diff == 0; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/g0001_0100/s0029_divide_two_integers/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0001_0100.s0029_divide_two_integers; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void divide() { 11 | assertThat(new Solution().divide(10, 3), equalTo(3)); 12 | } 13 | 14 | @Test 15 | void divide2() { 16 | assertThat(new Solution().divide(7, -3), equalTo(-2)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0001_0100/s0052_n_queens_ii/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0001_0100.s0052_n_queens_ii; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void totalNQueens() { 11 | assertThat(new Solution().totalNQueens(4), equalTo(2)); 12 | } 13 | 14 | @Test 15 | void totalNQueens2() { 16 | assertThat(new Solution().totalNQueens(1), equalTo(1)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0201_0300/s0279_perfect_squares/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0201_0300.s0279_perfect_squares; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void numSquares() { 11 | assertThat(new Solution().numSquares(12), equalTo(3)); 12 | } 13 | 14 | @Test 15 | void numSquares2() { 16 | assertThat(new Solution().numSquares(13), equalTo(2)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0301_0400/s0371_sum_of_two_integers/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0301_0400.s0371_sum_of_two_integers; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void getSum() { 11 | assertThat(new Solution().getSum(1, 2), equalTo(3)); 12 | } 13 | 14 | @Test 15 | void getSum2() { 16 | assertThat(new Solution().getSum(2, 3), equalTo(5)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0701_0800/s0754_reach_a_number/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0701_0800.s0754_reach_a_number; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void reachNumber() { 11 | assertThat(new Solution().reachNumber(2), equalTo(3)); 12 | } 13 | 14 | @Test 15 | void reachNumber2() { 16 | assertThat(new Solution().reachNumber(3), equalTo(2)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/g2301_2400/s2335_minimum_amount_of_time_to_fill_cups/Solution.java: -------------------------------------------------------------------------------- 1 | package g2301_2400.s2335_minimum_amount_of_time_to_fill_cups; 2 | 3 | // #Easy #Array #Greedy #Heap_Priority_Queue #2022_07_13_Time_1_ms_(97.92%)_Space_41.6_MB_(68.17%) 4 | 5 | import java.util.Arrays; 6 | 7 | public class Solution { 8 | public int fillCups(int[] amount) { 9 | Arrays.sort(amount); 10 | int sum = amount[0] + amount[1] + amount[2]; 11 | return (amount[0] + amount[1] < amount[2]) ? amount[2] : (sum + 1) / 2; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/g2501_2600/s2544_alternating_digit_sum/Solution.java: -------------------------------------------------------------------------------- 1 | package g2501_2600.s2544_alternating_digit_sum; 2 | 3 | // #Easy #Math #2023_05_11_Time_0_ms_(100.00%)_Space_39.4_MB_(79.49%) 4 | 5 | public class Solution { 6 | public int alternateDigitSum(int n) { 7 | String s = Integer.toString(n); 8 | char[] arr = s.toCharArray(); 9 | int res = 0; 10 | for (int i = 0; i < arr.length; i++) { 11 | res += (int) Math.pow(-1, i) * (arr[i] - '0'); 12 | } 13 | return res; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g2701_2800/s2798_number_of_employees_who_met_the_target/Solution.java: -------------------------------------------------------------------------------- 1 | package g2701_2800.s2798_number_of_employees_who_met_the_target; 2 | 3 | // #Easy #Array #Enumeration #2023_09_14_Time_0_ms_(100.00%)_Space_40.6_MB_(98.10%) 4 | 5 | public class Solution { 6 | public int numberOfEmployeesWhoMetTarget(int[] hours, int target) { 7 | int count = 0; 8 | for (int i : hours) { 9 | if (i >= target) { 10 | count++; 11 | } 12 | } 13 | return count; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g2901_3000/s2923_find_champion_i/Solution.java: -------------------------------------------------------------------------------- 1 | package g2901_3000.s2923_find_champion_i; 2 | 3 | // #Easy #Array #Matrix #2023_12_29_Time_1_ms_(96.00%)_Space_45.2_MB_(6.05%) 4 | 5 | public class Solution { 6 | public int findChampion(int[][] grid) { 7 | int champion = grid[1][0]; 8 | for (int opponent = 2; opponent < grid.length; opponent++) { 9 | if (grid[opponent][champion] != 0) { 10 | champion = opponent; 11 | } 12 | } 13 | return champion; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g3601_3700/s3683_earliest_time_to_finish_one_task/Solution.java: -------------------------------------------------------------------------------- 1 | package g3601_3700.s3683_earliest_time_to_finish_one_task; 2 | 3 | // #Easy #Array #Weekly_Contest_467 #2025_09_26_Time_1_ms_(77.01%)_Space_45.24_MB_(38.70%) 4 | 5 | public class Solution { 6 | public int earliestTime(int[][] tasks) { 7 | int ans = 1000; 8 | for (int[] task : tasks) { 9 | int st = task[0]; 10 | int tm = task[1]; 11 | ans = Math.min(ans, st + tm); 12 | } 13 | return ans; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/g0001_0100/s0062_unique_paths/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0001_0100.s0062_unique_paths; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void uniquePaths() { 11 | assertThat(new Solution().uniquePaths(3, 7), equalTo(28)); 12 | } 13 | 14 | @Test 15 | void uniquePaths2() { 16 | assertThat(new Solution().uniquePaths(3, 2), equalTo(3)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0001_0100/s0070_climbing_stairs/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0001_0100.s0070_climbing_stairs; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void climbStairs() { 11 | assertThat(new Solution().climbStairs(2), equalTo(2)); 12 | } 13 | 14 | @Test 15 | void climbStairs2() { 16 | assertThat(new Solution().climbStairs(3), equalTo(3)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0301_0400/s0343_integer_break/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0301_0400.s0343_integer_break; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void integerBreak() { 11 | assertThat(new Solution().integerBreak(2), equalTo(1)); 12 | } 13 | 14 | @Test 15 | void integerBreak2() { 16 | assertThat(new Solution().integerBreak(10), equalTo(36)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g1001_1100/s1025_divisor_game/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g1001_1100.s1025_divisor_game; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void divisorGame() { 11 | assertThat(new Solution().divisorGame(2), equalTo(true)); 12 | } 13 | 14 | @Test 15 | void divisorGame2() { 16 | assertThat(new Solution().divisorGame(3), equalTo(false)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g2401_2500/s2429_minimize_xor/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g2401_2500.s2429_minimize_xor; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void minimizeXor() { 11 | assertThat(new Solution().minimizeXor(3, 5), equalTo(3)); 12 | } 13 | 14 | @Test 15 | void minimizeXor2() { 16 | assertThat(new Solution().minimizeXor(1, 12), equalTo(3)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g2601_2700/s2648_generate_fibonacci_sequence/solution.test.ts: -------------------------------------------------------------------------------- 1 | // tslint:disable:no-magic-numbers 2 | import { fibGenerator } from 'src/main/java/g2601_2700/s2648_generate_fibonacci_sequence/solution' 3 | import { expect, test } from 'vitest' 4 | 5 | test('fibGenerator', () => { 6 | const gen = fibGenerator() 7 | expect(gen.next().value).toEqual(0) 8 | expect(gen.next().value).toEqual(1) 9 | expect(gen.next().value).toEqual(1) 10 | expect(gen.next().value).toEqual(2) 11 | expect(gen.next().value).toEqual(3) 12 | }) 13 | -------------------------------------------------------------------------------- /src/test/java/g2601_2700/s2667_create_hello_world_function/solution.test.ts: -------------------------------------------------------------------------------- 1 | // tslint:disable:no-magic-numbers 2 | import { createHelloWorld } from 'src/main/java/g2601_2700/s2667_create_hello_world_function/solution' 3 | import { expect, test } from 'vitest' 4 | 5 | test('createHelloWorld', () => { 6 | const counter = createHelloWorld() 7 | expect(counter()).toEqual('Hello World') 8 | }) 9 | 10 | test('createHelloWorld2', () => { 11 | const counter = createHelloWorld() 12 | expect(counter({}, null, 42)).toEqual('Hello World') 13 | }) 14 | -------------------------------------------------------------------------------- /src/main/java/g0101_0200/s0185_department_top_three_salaries/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Hard #Database #2022_06_27_Time_643_ms_(95.52%)_Space_0B_(100.00%) 3 | SELECT D.name AS Department, 4 | A.name AS Employee, 5 | A.salary AS Salary 6 | FROM 7 | (SELECT *, 8 | dense_rank() over(PARTITION BY departmentID 9 | ORDER BY salary DESC) AS rn 10 | FROM Employee) A 11 | INNER JOIN Department D ON A.departmentid = D.id 12 | WHERE A.rn < 4 13 | ORDER BY Department, Salary DESC 14 | -------------------------------------------------------------------------------- /src/main/java/g1701_1800/s1780_check_if_number_is_a_sum_of_powers_of_three/Solution.java: -------------------------------------------------------------------------------- 1 | package g1701_1800.s1780_check_if_number_is_a_sum_of_powers_of_three; 2 | 3 | // #Medium #Math #2022_07_14_Time_0_ms_(100.00%)_Space_39_MB_(98.65%) 4 | 5 | public class Solution { 6 | public boolean checkPowersOfThree(int n) { 7 | while (n != 0) { 8 | int rem = n % 3; 9 | n /= 3; 10 | if (rem == 2 || n == 2) { 11 | return false; 12 | } 13 | } 14 | return true; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/g1901_2000/s1967_number_of_strings_that_appear_as_substrings_in_word/Solution.java: -------------------------------------------------------------------------------- 1 | package g1901_2000.s1967_number_of_strings_that_appear_as_substrings_in_word; 2 | 3 | // #Easy #String #2022_06_19_Time_1_ms_(82.02%)_Space_42.5_MB_(54.47%) 4 | 5 | public class Solution { 6 | public int numOfStrings(String[] patterns, String word) { 7 | int res = 0; 8 | for (String p : patterns) { 9 | if (word.contains(p)) { 10 | res++; 11 | } 12 | } 13 | return res; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g2701_2800/s2778_sum_of_squares_of_special_elements/Solution.java: -------------------------------------------------------------------------------- 1 | package g2701_2800.s2778_sum_of_squares_of_special_elements; 2 | 3 | // #Easy #Array #Simulation #2023_09_21_Time_1_ms_(100.00%)_Space_42.8_MB_(94.54%) 4 | 5 | public class Solution { 6 | public int sumOfSquares(int[] nums) { 7 | int sum = 0; 8 | for (int i = 0; i < nums.length; i++) { 9 | if (nums.length % (i + 1) == 0) { 10 | sum += nums[i] * nums[i]; 11 | } 12 | } 13 | return sum; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com_github_leetcode/EmployeeTest.java: -------------------------------------------------------------------------------- 1 | package com_github_leetcode; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class EmployeeTest { 9 | @Test 10 | void constructor() { 11 | Employee employee = new Employee(1, 2, null); 12 | assertThat(employee.id, equalTo(1)); 13 | assertThat(employee.importance, equalTo(2)); 14 | assertThat(employee.subordinates, equalTo(null)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/g0201_0300/s0264_ugly_number_ii/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0201_0300.s0264_ugly_number_ii; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void nthUglyNumber() { 11 | assertThat(new Solution().nthUglyNumber(10), equalTo(12)); 12 | } 13 | 14 | @Test 15 | void nthUglyNumber2() { 16 | assertThat(new Solution().nthUglyNumber(1), equalTo(1)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0201_0300/s0274_h_index/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0201_0300.s0274_h_index; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void hIndex() { 11 | assertThat(new Solution().hIndex(new int[] {3, 0, 6, 1, 5}), equalTo(3)); 12 | } 13 | 14 | @Test 15 | void hIndex2() { 16 | assertThat(new Solution().hIndex(new int[] {1, 3, 1}), equalTo(1)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0401_0500/s0481_magical_string/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0401_0500.s0481_magical_string; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void magicalString() { 11 | assertThat(new Solution().magicalString(6), equalTo(3)); 12 | } 13 | 14 | @Test 15 | void magicalString2() { 16 | assertThat(new Solution().magicalString(1), equalTo(1)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0501_0600/s0504_base_7/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0501_0600.s0504_base_7; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void convertToBase7() { 11 | assertThat(new Solution().convertToBase7(100), equalTo("202")); 12 | } 13 | 14 | @Test 15 | void convertToBase72() { 16 | assertThat(new Solution().convertToBase7(-7), equalTo("-10")); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0601_0700/s0670_maximum_swap/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0601_0700.s0670_maximum_swap; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void maximumSwap() { 11 | assertThat(new Solution().maximumSwap(2736), equalTo(7236)); 12 | } 13 | 14 | @Test 15 | void maximumSwap2() { 16 | assertThat(new Solution().maximumSwap(9973), equalTo(9973)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g2701_2800/s2719_count_of_integers/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g2701_2800.s2719_count_of_integers; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void count() { 11 | assertThat(new Solution().count("1", "12", 1, 8), equalTo(11)); 12 | } 13 | 14 | @Test 15 | void count2() { 16 | assertThat(new Solution().count("1", "5", 1, 5), equalTo(5)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g3101_3200/s3174_clear_digits/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g3101_3200.s3174_clear_digits; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void clearDigits() { 11 | assertThat(new Solution().clearDigits("abc"), equalTo("abc")); 12 | } 13 | 14 | @Test 15 | void clearDigits2() { 16 | assertThat(new Solution().clearDigits("cb34"), equalTo("")); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "maven" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "weekly" 12 | -------------------------------------------------------------------------------- /src/main/java/g0101_0200/s0172_factorial_trailing_zeroes/Solution.java: -------------------------------------------------------------------------------- 1 | package g0101_0200.s0172_factorial_trailing_zeroes; 2 | 3 | // #Medium #Top_Interview_Questions #Math #Udemy_Integers #Top_Interview_150_Math 4 | // #2025_03_09_Time_0_ms_(100.00%)_Space_40.78_MB_(46.99%) 5 | 6 | public class Solution { 7 | public int trailingZeroes(int n) { 8 | int base = 5; 9 | int count = 0; 10 | while (n >= base) { 11 | count += n / base; 12 | base = base * 5; 13 | } 14 | return count; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/g0501_0600/s0575_distribute_candies/Solution.java: -------------------------------------------------------------------------------- 1 | package g0501_0600.s0575_distribute_candies; 2 | 3 | // #Easy #Array #Hash_Table #2022_08_10_Time_67_ms_(42.81%)_Space_111.2_MB_(25.92%) 4 | 5 | import java.util.HashSet; 6 | import java.util.Set; 7 | 8 | public class Solution { 9 | public int distributeCandies(int[] candyType) { 10 | Set set = new HashSet<>(); 11 | for (int i : candyType) { 12 | set.add(i); 13 | } 14 | return Math.min(set.size(), candyType.length / 2); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/g1601_1700/s1668_maximum_repeating_substring/Solution.java: -------------------------------------------------------------------------------- 1 | package g1601_1700.s1668_maximum_repeating_substring; 2 | 3 | // #Easy #String #String_Matching #2022_04_22_Time_1_ms_(93.15%)_Space_40.5_MB_(86.13%) 4 | 5 | public class Solution { 6 | public int maxRepeating(String sequence, String word) { 7 | int k = 0; 8 | StringBuilder repeat = new StringBuilder(word); 9 | while (sequence.contains(repeat)) { 10 | k++; 11 | repeat.append(word); 12 | } 13 | return k; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g3201_3300/s3282_reach_end_of_array_with_max_score/Solution.java: -------------------------------------------------------------------------------- 1 | package g3201_3300.s3282_reach_end_of_array_with_max_score; 2 | 3 | // #Medium #Array #Greedy #2024_09_09_Time_9_ms_(100.00%)_Space_63.2_MB_(100.00%) 4 | 5 | import java.util.List; 6 | 7 | public class Solution { 8 | public long findMaximumScore(List nums) { 9 | long res = 0; 10 | long ma = 0; 11 | for (int num : nums) { 12 | res += ma; 13 | ma = Math.max(ma, num); 14 | } 15 | return res; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/g0001_0100/s0067_add_binary/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0001_0100.s0067_add_binary; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void addBinary() { 11 | assertThat(new Solution().addBinary("11", "1"), equalTo("100")); 12 | } 13 | 14 | @Test 15 | void addBinary2() { 16 | assertThat(new Solution().addBinary("1010", "1011"), equalTo("10101")); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0001_0100/s0096_unique_binary_search_trees/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0001_0100.s0096_unique_binary_search_trees; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void numTrees() { 11 | assertThat(new Solution().numTrees(3), equalTo(5)); 12 | } 13 | 14 | @Test 15 | void numTrees2() { 16 | assertThat(new Solution().numTrees(1), equalTo(1)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0301_0400/s0390_elimination_game/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0301_0400.s0390_elimination_game; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void lastRemaining() { 11 | assertThat(new Solution().lastRemaining(9), equalTo(6)); 12 | } 13 | 14 | @Test 15 | void lastRemaining2() { 16 | assertThat(new Solution().lastRemaining(1), equalTo(1)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0701_0800/s0753_cracking_the_safe/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0701_0800.s0753_cracking_the_safe; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void crackSafe() { 11 | assertThat(new Solution().crackSafe(1, 2), equalTo("01")); 12 | } 13 | 14 | @Test 15 | void crackSafe2() { 16 | assertThat(new Solution().crackSafe(2, 2), equalTo("00110")); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0801_0900/s0808_soup_servings/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0801_0900.s0808_soup_servings; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void soupServings() { 11 | assertThat(new Solution().soupServings(50), equalTo(0.625)); 12 | } 13 | 14 | @Test 15 | void soupServings2() { 16 | assertThat(new Solution().soupServings(100), equalTo(0.71875)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g1801_1900/s1837_sum_of_digits_in_base_k/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g1801_1900.s1837_sum_of_digits_in_base_k; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void sumBase() { 11 | assertThat(new Solution().sumBase(34, 6), equalTo(9)); 12 | } 13 | 14 | @Test 15 | void sumBase2() { 16 | assertThat(new Solution().sumBase(10, 10), equalTo(1)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g2501_2600/s2578_split_with_minimum_sum/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g2501_2600.s2578_split_with_minimum_sum; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void splitNum() { 11 | assertThat(new Solution().splitNum(4325), equalTo(59)); 12 | } 13 | 14 | @Test 15 | void splitNum2() { 16 | assertThat(new Solution().splitNum(687), equalTo(75)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/g0001_0100/s0047_permutations_ii/readme.md: -------------------------------------------------------------------------------- 1 | 47\. Permutations II 2 | 3 | Medium 4 | 5 | Given a collection of numbers, `nums`, that might contain duplicates, return _all possible unique permutations **in any order**._ 6 | 7 | **Example 1:** 8 | 9 | **Input:** nums = [1,1,2] 10 | 11 | **Output:** [[1,1,2], [1,2,1], [2,1,1]] 12 | 13 | **Example 2:** 14 | 15 | **Input:** nums = [1,2,3] 16 | 17 | **Output:** [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] 18 | 19 | **Constraints:** 20 | 21 | * `1 <= nums.length <= 8` 22 | * `-10 <= nums[i] <= 10` -------------------------------------------------------------------------------- /src/main/java/g0101_0200/s0137_single_number_ii/Solution.java: -------------------------------------------------------------------------------- 1 | package g0101_0200.s0137_single_number_ii; 2 | 3 | // #Medium #Array #Bit_Manipulation #Top_Interview_150_Bit_Manipulation 4 | // #2025_03_06_Time_0_ms_(100.00%)_Space_45.39_MB_(79.09%) 5 | 6 | public class Solution { 7 | public int singleNumber(int[] nums) { 8 | int ones = 0; 9 | int twos = 0; 10 | for (int num : nums) { 11 | ones = (ones ^ num) & (~twos); 12 | twos = (twos ^ num) & (~ones); 13 | } 14 | return ones; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/g0501_0600/s0561_array_partition_i/Solution.java: -------------------------------------------------------------------------------- 1 | package g0501_0600.s0561_array_partition_i; 2 | 3 | // #Easy #Array #Sorting #Greedy #Counting_Sort 4 | // #2022_08_03_Time_14_ms_(84.99%)_Space_44.2_MB_(95.29%) 5 | 6 | import java.util.Arrays; 7 | 8 | public class Solution { 9 | public int arrayPairSum(int[] nums) { 10 | Arrays.sort(nums); 11 | int sum = 0; 12 | for (int i = 0; i < nums.length - 1; i = i + 2) { 13 | sum += Math.min(nums[i], nums[i + 1]); 14 | } 15 | return sum; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/g2401_2500/s2433_find_the_original_array_of_prefix_xor/Solution.java: -------------------------------------------------------------------------------- 1 | package g2401_2500.s2433_find_the_original_array_of_prefix_xor; 2 | 3 | // #Medium #Array #Bit_Manipulation #2022_12_07_Time_2_ms_(96.00%)_Space_54.8_MB_(93.08%) 4 | 5 | public class Solution { 6 | public int[] findArray(int[] pref) { 7 | int[] result = new int[pref.length]; 8 | result[0] = pref[0]; 9 | for (int i = 1; i < pref.length; i++) { 10 | result[i] = pref[i] ^ pref[i - 1]; 11 | } 12 | return result; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/g2701_2800/s2745_construct_the_longest_new_string/Solution.java: -------------------------------------------------------------------------------- 1 | package g2701_2800.s2745_construct_the_longest_new_string; 2 | 3 | // #Medium #Math #Greedy #Brainteaser #2023_09_23_Time_1_ms_(100.00%)_Space_40.1_MB_(66.80%) 4 | 5 | public class Solution { 6 | public int longestString(int x, int y, int z) { 7 | int min = Math.min(x, y); 8 | int res; 9 | if (x == y) { 10 | res = 2 * min + z; 11 | } else { 12 | res = 2 * min + 1 + z; 13 | } 14 | return res * 2; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/g0001_0100/s0043_multiply_strings/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0001_0100.s0043_multiply_strings; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void multiply() { 11 | assertThat(new Solution().multiply("2", "3"), equalTo("6")); 12 | } 13 | 14 | @Test 15 | void multiply2() { 16 | assertThat(new Solution().multiply("123", "456"), equalTo("56088")); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0001_0100/s0045_jump_game_ii/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0001_0100.s0045_jump_game_ii; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void jump() { 11 | assertThat(new Solution().jump(new int[] {2, 3, 1, 1, 4}), equalTo(2)); 12 | } 13 | 14 | @Test 15 | void jump2() { 16 | assertThat(new Solution().jump(new int[] {2, 3, 0, 1, 4}), equalTo(2)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0201_0300/s0233_number_of_digit_one/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0201_0300.s0233_number_of_digit_one; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void countDigitOne() { 11 | assertThat(new Solution().countDigitOne(13), equalTo(6)); 12 | } 13 | 14 | @Test 15 | void countDigitOne2() { 16 | assertThat(new Solution().countDigitOne(0), equalTo(0)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0201_0300/s0275_h_index_ii/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0201_0300.s0275_h_index_ii; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void hIndex() { 11 | assertThat(new Solution().hIndex(new int[] {0, 1, 3, 5, 6}), equalTo(3)); 12 | } 13 | 14 | @Test 15 | void hIndex2() { 16 | assertThat(new Solution().hIndex(new int[] {1, 2, 100}), equalTo(2)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0401_0500/s0415_add_strings/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0401_0500.s0415_add_strings; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void addStrings() { 11 | assertThat(new Solution().addStrings("11", "123"), equalTo("134")); 12 | } 13 | 14 | @Test 15 | void addStrings2() { 16 | assertThat(new Solution().addStrings("456", "77"), equalTo("533")); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0401_0500/s0476_number_complement/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0401_0500.s0476_number_complement; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void findComplement() { 11 | assertThat(new Solution().findComplement(5), equalTo(2)); 12 | } 13 | 14 | @Test 15 | void findComplement2() { 16 | assertThat(new Solution().findComplement(1), equalTo(0)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g1101_1200/s1137_n_th_tribonacci_number/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g1101_1200.s1137_n_th_tribonacci_number; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void tribonacci() { 11 | assertThat(new Solution().tribonacci(4), equalTo(4)); 12 | } 13 | 14 | @Test 15 | void tribonacci2() { 16 | assertThat(new Solution().tribonacci(25), equalTo(1389537)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g2501_2600/s2514_count_anagrams/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g2501_2600.s2514_count_anagrams; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void countAnagrams() { 11 | assertThat(new Solution().countAnagrams("too hot"), equalTo(18)); 12 | } 13 | 14 | @Test 15 | void countAnagrams2() { 16 | assertThat(new Solution().countAnagrams("aa"), equalTo(1)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g2501_2600/s2582_pass_the_pillow/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g2501_2600.s2582_pass_the_pillow; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void passThePillow() { 11 | assertThat(new Solution().passThePillow(4, 5), equalTo(2)); 12 | } 13 | 14 | @Test 15 | void passThePillow2() { 16 | assertThat(new Solution().passThePillow(3, 2), equalTo(3)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/g0401_0500/s0479_largest_palindrome_product/readme.md: -------------------------------------------------------------------------------- 1 | 479\. Largest Palindrome Product 2 | 3 | Hard 4 | 5 | Given an integer n, return _the **largest palindromic integer** that can be represented as the product of two `n`\-digits integers_. Since the answer can be very large, return it **modulo** `1337`. 6 | 7 | **Example 1:** 8 | 9 | **Input:** n = 2 10 | 11 | **Output:** 987 Explanation: 99 x 91 = 9009, 9009 % 1337 = 987 12 | 13 | **Example 2:** 14 | 15 | **Input:** n = 1 16 | 17 | **Output:** 9 18 | 19 | **Constraints:** 20 | 21 | * `1 <= n <= 8` -------------------------------------------------------------------------------- /src/main/java/g1101_1200/s1108_defanging_an_ip_address/readme.md: -------------------------------------------------------------------------------- 1 | 1108\. Defanging an IP Address 2 | 3 | Easy 4 | 5 | Given a valid (IPv4) IP `address`, return a defanged version of that IP address. 6 | 7 | A _defanged IP address_ replaces every period `"."` with `"[.]"`. 8 | 9 | **Example 1:** 10 | 11 | **Input:** address = "1.1.1.1" 12 | 13 | **Output:** "1[.]1[.]1[.]1" 14 | 15 | **Example 2:** 16 | 17 | **Input:** address = "255.100.50.0" 18 | 19 | **Output:** "255[.]100[.]50[.]0" 20 | 21 | **Constraints:** 22 | 23 | * The given `address` is a valid IPv4 address. -------------------------------------------------------------------------------- /src/main/java/g1101_1200/s1193_monthly_transactions_i/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #Database #2023_08_12_Time_961_ms_(88.29%)_Space_0B_(100.00%) 3 | SELECT 4 | FORMATDATETIME(trans_date, 'yyyy-MM') AS trans_month, 5 | country, 6 | COUNT(*) AS trans_count, 7 | SUM(CASE WHEN state = 'approved' THEN 1 ELSE 0 END) AS approved_count, 8 | SUM(amount) AS trans_total_amount, 9 | SUM(CASE WHEN state = 'approved' THEN amount ELSE 0 END) AS approved_total_amount 10 | FROM Transactions 11 | GROUP BY trans_month, country; 12 | -------------------------------------------------------------------------------- /src/main/java/g1401_1500/s1480_running_sum_of_1d_array/Solution.java: -------------------------------------------------------------------------------- 1 | package g1401_1500.s1480_running_sum_of_1d_array; 2 | 3 | // #Easy #Array #Prefix_Sum #Level_1_Day_1_Prefix_Sum 4 | // #2022_04_04_Time_0_ms_(100.00%)_Space_42.9_MB_(76.13%) 5 | 6 | public class Solution { 7 | public int[] runningSum(int[] nums) { 8 | int sum = 0; 9 | int[] result = new int[nums.length]; 10 | for (int i = 0; i < nums.length; i++) { 11 | sum += nums[i]; 12 | result[i] = sum; 13 | } 14 | return result; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/g1901_2000/s1955_count_number_of_special_subsequences/Solution.java: -------------------------------------------------------------------------------- 1 | package g1901_2000.s1955_count_number_of_special_subsequences; 2 | 3 | // #Hard #Array #Dynamic_Programming #2022_05_18_Time_22_ms_(80.65%)_Space_121_MB_(27.42%) 4 | 5 | public class Solution { 6 | public int countSpecialSubsequences(int[] nums) { 7 | int mod = 1000000007; 8 | int[] dp = new int[] {1, 0, 0, 0}; 9 | for (int n : nums) { 10 | dp[n + 1] = (dp[n] + 2 * dp[n + 1] % mod) % mod; 11 | } 12 | return dp[3]; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/g2201_2300/s2278_percentage_of_letter_in_string/Solution.java: -------------------------------------------------------------------------------- 1 | package g2201_2300.s2278_percentage_of_letter_in_string; 2 | 3 | // #Easy #String #2022_06_18_Time_0_ms_(100.00%)_Space_40.1_MB_(95.65%) 4 | 5 | public class Solution { 6 | public int percentageLetter(String s, char letter) { 7 | int count = 0; 8 | int n = s.length(); 9 | for (int i = 0; i < n; i++) { 10 | if (s.charAt(i) == letter) { 11 | ++count; 12 | } 13 | } 14 | return (count * 100) / (n); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/g2601_2700/s2629_function_composition/solution.ts: -------------------------------------------------------------------------------- 1 | // #Easy #2023_08_31_Time_58_ms_(95.63%)_Space_45.3_MB_(73.06%) 2 | 3 | type F = (x: number) => number 4 | 5 | function compose(functions: F[]): F { 6 | return function (x) { 7 | if (functions.length == 0) return x 8 | for (let ind = functions.length - 1; ind >= 0; ind--) { 9 | x = functions[ind](x) 10 | } 11 | return x 12 | } 13 | } 14 | 15 | /* 16 | * const fn = compose([x => x + 1, x => 2 * x]) 17 | * fn(4) // 9 18 | */ 19 | 20 | export { compose } 21 | -------------------------------------------------------------------------------- /src/main/java/g3101_3200/s3190_find_minimum_operations_to_make_all_elements_divisible_by_three/Solution.java: -------------------------------------------------------------------------------- 1 | package g3101_3200.s3190_find_minimum_operations_to_make_all_elements_divisible_by_three; 2 | 3 | // #Easy #Array #Math #2024_06_26_Time_0_ms_(100.00%)_Space_41.6_MB_(78.56%) 4 | 5 | public class Solution { 6 | public int minimumOperations(int[] nums) { 7 | int count = 0; 8 | for (int num : nums) { 9 | if (num % 3 != 0) { 10 | count++; 11 | } 12 | } 13 | return count; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/g0101_0200/s0164_maximum_gap/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0101_0200.s0164_maximum_gap; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void maximumGap() { 11 | assertThat(new Solution().maximumGap(new int[] {3, 6, 9, 1}), equalTo(3)); 12 | } 13 | 14 | @Test 15 | void maximumGap2() { 16 | assertThat(new Solution().maximumGap(new int[] {10}), equalTo(0)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0401_0500/s0405_convert_a_number_to_hexadecimal/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0401_0500.s0405_convert_a_number_to_hexadecimal; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void toHex() { 11 | assertThat(new Solution().toHex(26), equalTo("1a")); 12 | } 13 | 14 | @Test 15 | void toHex2() { 16 | assertThat(new Solution().toHex(-1), equalTo("ffffffff")); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0601_0700/s0664_strange_printer/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0601_0700.s0664_strange_printer; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void strangePrinter() { 11 | assertThat(new Solution().strangePrinter("aaabbb"), equalTo(2)); 12 | } 13 | 14 | @Test 15 | void strangePrinter2() { 16 | assertThat(new Solution().strangePrinter("aba"), equalTo(2)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0601_0700/s0677_map_sum_pairs/MapSumTest.java: -------------------------------------------------------------------------------- 1 | package g0601_0700.s0677_map_sum_pairs; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class MapSumTest { 9 | @Test 10 | void mapSumTest() { 11 | MapSum mapSum = new MapSum(); 12 | mapSum.insert("apple", 3); 13 | assertThat(mapSum.sum("ap"), equalTo(3)); 14 | mapSum.insert("app", 2); 15 | assertThat(mapSum.sum("ap"), equalTo(5)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/g1501_1600/s1518_water_bottles/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g1501_1600.s1518_water_bottles; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void numWaterBottles() { 11 | assertThat(new Solution().numWaterBottles(9, 3), equalTo(13)); 12 | } 13 | 14 | @Test 15 | void numWaterBottles2() { 16 | assertThat(new Solution().numWaterBottles(15, 4), equalTo(19)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g1801_1900/s1871_jump_game_vii/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g1801_1900.s1871_jump_game_vii; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void canReach() { 11 | assertThat(new Solution().canReach("011010", 2, 3), equalTo(true)); 12 | } 13 | 14 | @Test 15 | void canReach2() { 16 | assertThat(new Solution().canReach("01101110", 2, 3), equalTo(false)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g1901_2000/s1925_count_square_sum_triples/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g1901_2000.s1925_count_square_sum_triples; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void countTriples() { 11 | assertThat(new Solution().countTriples(5), equalTo(2)); 12 | } 13 | 14 | @Test 15 | void countTriples2() { 16 | assertThat(new Solution().countTriples(10), equalTo(4)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g2401_2500/s2498_frog_jump_ii/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g2401_2500.s2498_frog_jump_ii; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void maxJump() { 11 | assertThat(new Solution().maxJump(new int[] {0, 2, 5, 6, 7}), equalTo(5)); 12 | } 13 | 14 | @Test 15 | void maxJump2() { 16 | assertThat(new Solution().maxJump(new int[] {0, 3, 9}), equalTo(9)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/g0301_0400/s0344_reverse_string/Solution.java: -------------------------------------------------------------------------------- 1 | package g0301_0400.s0344_reverse_string; 2 | 3 | // #Easy #String #Two_Pointers #Recursion #Algorithm_I_Day_4_Two_Pointers #Udemy_Strings 4 | // #2022_07_11_Time_1_ms_(99.91%)_Space_54.4_MB_(64.26%) 5 | 6 | public class Solution { 7 | public void reverseString(char[] s) { 8 | int left = 0; 9 | int right = s.length - 1; 10 | while (left < right) { 11 | char tmp = s[left]; 12 | s[left++] = s[right]; 13 | s[right--] = tmp; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/g0301_0400/s0386_lexicographical_numbers/readme.md: -------------------------------------------------------------------------------- 1 | 386\. Lexicographical Numbers 2 | 3 | Medium 4 | 5 | Given an integer `n`, return all the numbers in the range `[1, n]` sorted in lexicographical order. 6 | 7 | You must write an algorithm that runs in `O(n)` time and uses `O(1)` extra space. 8 | 9 | **Example 1:** 10 | 11 | **Input:** n = 13 12 | 13 | **Output:** [1,10,11,12,13,2,3,4,5,6,7,8,9] 14 | 15 | **Example 2:** 16 | 17 | **Input:** n = 2 18 | 19 | **Output:** [1,2] 20 | 21 | **Constraints:** 22 | 23 | * 1 <= n <= 5 * 104 -------------------------------------------------------------------------------- /src/main/java/g0701_0800/s0709_to_lower_case/Solution.java: -------------------------------------------------------------------------------- 1 | package g0701_0800.s0709_to_lower_case; 2 | 3 | // #Easy #String #Programming_Skills_I_Day_9_String 4 | // #2022_03_23_Time_1_ms_(71.74%)_Space_42_MB_(52.94%) 5 | 6 | public class Solution { 7 | public String toLowerCase(String s) { 8 | char[] c = s.toCharArray(); 9 | for (int i = 0; i < s.length(); i++) { 10 | if (c[i] <= 'Z' && c[i] >= 'A') { 11 | c[i] = (char) (c[i] - 'A' + 'a'); 12 | } 13 | } 14 | return new String(c); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/g0701_0800/s0767_reorganize_string/readme.md: -------------------------------------------------------------------------------- 1 | 767\. Reorganize String 2 | 3 | Medium 4 | 5 | Given a string `s`, rearrange the characters of `s` so that any two adjacent characters are not the same. 6 | 7 | Return _any possible rearrangement of_ `s` _or return_ `""` _if not possible_. 8 | 9 | **Example 1:** 10 | 11 | **Input:** s = "aab" 12 | 13 | **Output:** "aba" 14 | 15 | **Example 2:** 16 | 17 | **Input:** s = "aaab" 18 | 19 | **Output:** "" 20 | 21 | **Constraints:** 22 | 23 | * `1 <= s.length <= 500` 24 | * `s` consists of lowercase English letters. -------------------------------------------------------------------------------- /src/main/java/g2901_3000/s2914_minimum_number_of_changes_to_make_binary_string_beautiful/Solution.java: -------------------------------------------------------------------------------- 1 | package g2901_3000.s2914_minimum_number_of_changes_to_make_binary_string_beautiful; 2 | 3 | // #Medium #String #2023_12_28_Time_3_ms_(99.56%)_Space_44.7_MB_(6.68%) 4 | 5 | public class Solution { 6 | public int minChanges(String s) { 7 | int ans = 0; 8 | for (int i = 0; i < s.length(); i += 2) { 9 | if (s.charAt(i) != s.charAt(i + 1)) { 10 | ans++; 11 | } 12 | } 13 | return ans; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/g0001_0100/s0055_jump_game/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0001_0100.s0055_jump_game; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void canJump() { 11 | assertThat(new Solution().canJump(new int[] {2, 3, 1, 1, 4}), equalTo(true)); 12 | } 13 | 14 | @Test 15 | void canJump2() { 16 | assertThat(new Solution().canJump(new int[] {3, 2, 1, 0, 4}), equalTo(false)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0201_0300/s0242_valid_anagram/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0201_0300.s0242_valid_anagram; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void isAnagram() { 11 | assertThat(new Solution().isAnagram("anagram", "nagaram"), equalTo(true)); 12 | } 13 | 14 | @Test 15 | void isAnagram2() { 16 | assertThat(new Solution().isAnagram("rat", "car"), equalTo(false)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0301_0400/s0312_burst_balloons/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0301_0400.s0312_burst_balloons; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void maxCoins() { 11 | assertThat(new Solution().maxCoins(new int[] {3, 1, 5, 8}), equalTo(167)); 12 | } 13 | 14 | @Test 15 | void maxCoins2() { 16 | assertThat(new Solution().maxCoins(new int[] {1, 5}), equalTo(10)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0401_0500/s0461_hamming_distance/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0401_0500.s0461_hamming_distance; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void hammingDistance() { 11 | assertThat(new Solution().hammingDistance(1, 4), equalTo(2)); 12 | } 13 | 14 | @Test 15 | void hammingDistance2() { 16 | assertThat(new Solution().hammingDistance(3, 1), equalTo(1)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0601_0700/s0629_k_inverse_pairs_array/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0601_0700.s0629_k_inverse_pairs_array; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void kInversePairs() { 11 | assertThat(new Solution().kInversePairs(3, 0), equalTo(1)); 12 | } 13 | 14 | @Test 15 | void kInversePairs2() { 16 | assertThat(new Solution().kInversePairs(3, 1), equalTo(2)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0601_0700/s0657_robot_return_to_origin/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0601_0700.s0657_robot_return_to_origin; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void judgeCircle() { 11 | assertThat(new Solution().judgeCircle("UD"), equalTo(true)); 12 | } 13 | 14 | @Test 15 | void judgeCircle2() { 16 | assertThat(new Solution().judgeCircle("LL"), equalTo(false)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0801_0900/s0854_k_similar_strings/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0801_0900.s0854_k_similar_strings; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void kSimilarity() { 11 | assertThat(new Solution().kSimilarity("ab", "ba"), equalTo(1)); 12 | } 13 | 14 | @Test 15 | void kSimilarity2() { 16 | assertThat(new Solution().kSimilarity("abc", "bca"), equalTo(2)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0801_0900/s0899_orderly_queue/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0801_0900.s0899_orderly_queue; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void orderlyQueue() { 11 | assertThat(new Solution().orderlyQueue("cba", 1), equalTo("acb")); 12 | } 13 | 14 | @Test 15 | void orderlyQueue2() { 16 | assertThat(new Solution().orderlyQueue("baaca", 3), equalTo("aaabc")); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g1401_1500/s1496_path_crossing/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g1401_1500.s1496_path_crossing; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void isPathCrossing() { 11 | assertThat(new Solution().isPathCrossing("NES"), equalTo(false)); 12 | } 13 | 14 | @Test 15 | void isPathCrossing2() { 16 | assertThat(new Solution().isPathCrossing("NESWW"), equalTo(true)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g2201_2300/s2262_total_appeal_of_a_string/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g2201_2300.s2262_total_appeal_of_a_string; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void appealSum() { 11 | assertThat(new Solution().appealSum("abbca"), equalTo(28L)); 12 | } 13 | 14 | @Test 15 | void appealSum2() { 16 | assertThat(new Solution().appealSum("code"), equalTo(20L)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g2601_2700/s2680_maximum_or/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g2601_2700.s2680_maximum_or; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void maximumOr() { 11 | assertThat(new Solution().maximumOr(new int[] {12, 9}, 1), equalTo(30L)); 12 | } 13 | 14 | @Test 15 | void maximumOr2() { 16 | assertThat(new Solution().maximumOr(new int[] {8, 1, 2}, 2), equalTo(35L)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g3001_3100/s3100_water_bottles_ii/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g3001_3100.s3100_water_bottles_ii; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void maxBottlesDrunk() { 11 | assertThat(new Solution().maxBottlesDrunk(13, 6), equalTo(15)); 12 | } 13 | 14 | @Test 15 | void maxBottlesDrunk2() { 16 | assertThat(new Solution().maxBottlesDrunk(10, 3), equalTo(13)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g3101_3200/s3110_score_of_a_string/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g3101_3200.s3110_score_of_a_string; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void scoreOfString() { 11 | assertThat(new Solution().scoreOfString("hello"), equalTo(13)); 12 | } 13 | 14 | @Test 15 | void scoreOfString2() { 16 | assertThat(new Solution().scoreOfString("zaz"), equalTo(50)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g3201_3300/s3271_hash_divided_string/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g3201_3300.s3271_hash_divided_string; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void stringHash() { 11 | assertThat(new Solution().stringHash("abcd", 2), equalTo("bf")); 12 | } 13 | 14 | @Test 15 | void stringHash2() { 16 | assertThat(new Solution().stringHash("mxz", 3), equalTo("i")); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g3301_3400/s3340_check_balanced_string/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g3301_3400.s3340_check_balanced_string; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void isBalanced() { 11 | assertThat(new Solution().isBalanced("1234"), equalTo(false)); 12 | } 13 | 14 | @Test 15 | void isBalanced2() { 16 | assertThat(new Solution().isBalanced("24123"), equalTo(true)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/g1201_1300/s1299_replace_elements_with_greatest_element_on_right_side/Solution.java: -------------------------------------------------------------------------------- 1 | package g1201_1300.s1299_replace_elements_with_greatest_element_on_right_side; 2 | 3 | // #Easy #Array #2022_03_10_Time_1_ms_(99.82%)_Space_54.3_MB_(34.76%) 4 | 5 | public class Solution { 6 | public int[] replaceElements(int[] arr) { 7 | int max = -1; 8 | for (int i = arr.length - 1; i >= 0; i--) { 9 | int temp = arr[i]; 10 | arr[i] = max; 11 | max = Math.max(max, temp); 12 | } 13 | return arr; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g3401_3500/s3427_sum_of_variable_length_subarrays/Solution.java: -------------------------------------------------------------------------------- 1 | package g3401_3500.s3427_sum_of_variable_length_subarrays; 2 | 3 | // #Easy #Array #Prefix_Sum #2025_01_22_Time_0_ms_(100.00%)_Space_43.77_MB_(58.41%) 4 | 5 | public class Solution { 6 | public int subarraySum(int[] nums) { 7 | int res = nums[0]; 8 | for (int i = 1; i < nums.length; i++) { 9 | int j = i - nums[i] - 1; 10 | nums[i] += nums[i - 1]; 11 | res += nums[i] - (j < 0 ? 0 : nums[j]); 12 | } 13 | return res; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g3601_3700/s3688_bitwise_or_of_even_numbers_in_an_array/Solution.java: -------------------------------------------------------------------------------- 1 | package g3601_3700.s3688_bitwise_or_of_even_numbers_in_an_array; 2 | 3 | // #Easy #Array #Bit_Manipulation #Simulation #Weekly_Contest_468 4 | // #2025_09_26_Time_0_ms_(100.00%)_Space_42.64_MB_(87.38%) 5 | 6 | public class Solution { 7 | public int evenNumberBitwiseORs(int[] nums) { 8 | int count = 0; 9 | for (int num : nums) { 10 | if (num % 2 == 0) { 11 | count |= num; 12 | } 13 | } 14 | return count; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/g0001_0100/s0072_edit_distance/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0001_0100.s0072_edit_distance; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void minDistance() { 11 | assertThat(new Solution().minDistance("horse", "ros"), equalTo(3)); 12 | } 13 | 14 | @Test 15 | void minDistance2() { 16 | assertThat(new Solution().minDistance("intention", "execution"), equalTo(5)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0001_0100/s0089_gray_code/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0001_0100.s0089_gray_code; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void grayCode() { 11 | assertThat(new Solution().grayCode(2).toArray(), equalTo(new int[] {0, 1, 3, 2})); 12 | } 13 | 14 | @Test 15 | void grayCode2() { 16 | assertThat(new Solution().grayCode(1).toArray(), equalTo(new int[] {0, 1})); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0301_0400/s0338_counting_bits/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0301_0400.s0338_counting_bits; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void countBits() { 11 | assertThat(new Solution().countBits(2), equalTo(new int[] {0, 1, 1})); 12 | } 13 | 14 | @Test 15 | void countBits2() { 16 | assertThat(new Solution().countBits(5), equalTo(new int[] {0, 1, 1, 2, 1, 2})); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0401_0500/s0414_third_maximum_number/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0401_0500.s0414_third_maximum_number; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void thirdMax() { 11 | assertThat(new Solution().thirdMax(new int[] {3, 2, 1}), equalTo(1)); 12 | } 13 | 14 | @Test 15 | void thirdMax2() { 16 | assertThat(new Solution().thirdMax(new int[] {1, 2}), equalTo(2)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0501_0600/s0526_beautiful_arrangement/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0501_0600.s0526_beautiful_arrangement; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void countArrangement() { 11 | assertThat(new Solution().countArrangement(2), equalTo(2)); 12 | } 13 | 14 | @Test 15 | void countArrangement2() { 16 | assertThat(new Solution().countArrangement(1), equalTo(1)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0501_0600/s0541_reverse_string_ii/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0501_0600.s0541_reverse_string_ii; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void reverseStr() { 11 | assertThat(new Solution().reverseStr("abcdefg", 2), equalTo("bacdfeg")); 12 | } 13 | 14 | @Test 15 | void reverseStr2() { 16 | assertThat(new Solution().reverseStr("abcd", 2), equalTo("bacd")); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0501_0600/s0576_out_of_boundary_paths/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0501_0600.s0576_out_of_boundary_paths; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void findPaths() { 11 | assertThat(new Solution().findPaths(2, 2, 2, 0, 0), equalTo(6)); 12 | } 13 | 14 | @Test 15 | void findPaths2() { 16 | assertThat(new Solution().findPaths(1, 3, 3, 0, 1), equalTo(12)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0601_0700/s0633_sum_of_square_numbers/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0601_0700.s0633_sum_of_square_numbers; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void judgeSquareSum() { 11 | assertThat(new Solution().judgeSquareSum(5), equalTo(true)); 12 | } 13 | 14 | @Test 15 | void judgeSquareSum2() { 16 | assertThat(new Solution().judgeSquareSum(3), equalTo(false)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0801_0900/s0877_stone_game/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0801_0900.s0877_stone_game; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void stoneGame() { 11 | assertThat(new Solution().stoneGame(new int[] {5, 3, 4, 5}), equalTo(true)); 12 | } 13 | 14 | @Test 15 | void stoneGame2() { 16 | assertThat(new Solution().stoneGame(new int[] {3, 7, 2, 3}), equalTo(true)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g1301_1400/s1323_maximum_69_number/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g1301_1400.s1323_maximum_69_number; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void maximum69Number() { 11 | assertThat(new Solution().maximum69Number(9996), equalTo(9999)); 12 | } 13 | 14 | @Test 15 | void maximum69Number2() { 16 | assertThat(new Solution().maximum69Number(9999), equalTo(9999)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g1301_1400/s1387_sort_integers_by_the_power_value/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g1301_1400.s1387_sort_integers_by_the_power_value; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void getKth() { 11 | assertThat(new Solution().getKth(12, 15, 2), equalTo(13)); 12 | } 13 | 14 | @Test 15 | void getKth2() { 16 | assertThat(new Solution().getKth(7, 11, 4), equalTo(7)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g1401_1500/s1446_consecutive_characters/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g1401_1500.s1446_consecutive_characters; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void maxPower() { 11 | assertThat(new Solution().maxPower("leetcode"), equalTo(2)); 12 | } 13 | 14 | @Test 15 | void maxPower2() { 16 | assertThat(new Solution().maxPower("abbcccddddeeeeedcba"), equalTo(5)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g1401_1500/s1486_xor_operation_in_an_array/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g1401_1500.s1486_xor_operation_in_an_array; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void xorOperation() { 11 | assertThat(new Solution().xorOperation(5, 0), equalTo(8)); 12 | } 13 | 14 | @Test 15 | void xorOperation2() { 16 | assertThat(new Solution().xorOperation(4, 3), equalTo(8)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g1501_1600/s1553_minimum_number_of_days_to_eat_n_oranges/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g1501_1600.s1553_minimum_number_of_days_to_eat_n_oranges; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void minDays() { 11 | assertThat(new Solution().minDays(10), equalTo(4)); 12 | } 13 | 14 | @Test 15 | void minDays2() { 16 | assertThat(new Solution().minDays(6), equalTo(3)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g2801_2900/s2810_faulty_keyboard/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g2801_2900.s2810_faulty_keyboard; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void finalString() { 11 | assertThat(new Solution().finalString("string"), equalTo("rtsng")); 12 | } 13 | 14 | @Test 15 | void finalString2() { 16 | assertThat(new Solution().finalString("poiinter"), equalTo("ponter")); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/g0201_0300/s0204_count_primes/readme.md: -------------------------------------------------------------------------------- 1 | 204\. Count Primes 2 | 3 | Medium 4 | 5 | Given an integer `n`, return _the number of prime numbers that are strictly less than_ `n`. 6 | 7 | **Example 1:** 8 | 9 | **Input:** n = 10 10 | 11 | **Output:** 4 12 | 13 | **Explanation:** There are 4 prime numbers less than 10, they are 2, 3, 5, 7. 14 | 15 | **Example 2:** 16 | 17 | **Input:** n = 0 18 | 19 | **Output:** 0 20 | 21 | **Example 3:** 22 | 23 | **Input:** n = 1 24 | 25 | **Output:** 0 26 | 27 | **Constraints:** 28 | 29 | * 0 <= n <= 5 * 106 -------------------------------------------------------------------------------- /src/main/java/g0701_0800/s0709_to_lower_case/readme.md: -------------------------------------------------------------------------------- 1 | 709\. To Lower Case 2 | 3 | Easy 4 | 5 | Given a string `s`, return _the string after replacing every uppercase letter with the same lowercase letter_. 6 | 7 | **Example 1:** 8 | 9 | **Input:** s = "Hello" 10 | 11 | **Output:** "hello" 12 | 13 | **Example 2:** 14 | 15 | **Input:** s = "here" 16 | 17 | **Output:** "here" 18 | 19 | **Example 3:** 20 | 21 | **Input:** s = "LOVELY" 22 | 23 | **Output:** "lovely" 24 | 25 | **Constraints:** 26 | 27 | * `1 <= s.length <= 100` 28 | * `s` consists of printable ASCII characters. -------------------------------------------------------------------------------- /src/main/java/g0801_0900/s0869_reordered_power_of_2/readme.md: -------------------------------------------------------------------------------- 1 | 869\. Reordered Power of 2 2 | 3 | Medium 4 | 5 | You are given an integer `n`. We reorder the digits in any order (including the original order) such that the leading digit is not zero. 6 | 7 | Return `true` _if and only if we can do this so that the resulting number is a power of two_. 8 | 9 | **Example 1:** 10 | 11 | **Input:** n = 1 12 | 13 | **Output:** true 14 | 15 | **Example 2:** 16 | 17 | **Input:** n = 10 18 | 19 | **Output:** false 20 | 21 | **Constraints:** 22 | 23 | * 1 <= n <= 109 -------------------------------------------------------------------------------- /src/main/java/g1001_1100/s1016_binary_string_with_substrings_representing_1_to_n/Solution.java: -------------------------------------------------------------------------------- 1 | package g1001_1100.s1016_binary_string_with_substrings_representing_1_to_n; 2 | 3 | // #Medium #String #2022_02_25_Time_0_ms_(100.00%)_Space_42.1_MB_(23.40%) 4 | 5 | public class Solution { 6 | public boolean queryString(String s, int n) { 7 | for (int i = 1; i <= n; i++) { 8 | String str = Integer.toBinaryString(i); 9 | if (!s.contains(str)) { 10 | return false; 11 | } 12 | } 13 | return true; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g1201_1300/s1287_element_appearing_more_than_25_in_sorted_array/Solution.java: -------------------------------------------------------------------------------- 1 | package g1201_1300.s1287_element_appearing_more_than_25_in_sorted_array; 2 | 3 | // #Easy #Array #2022_03_11_Time_0_ms_(100.00%)_Space_46.7_MB_(65.15%) 4 | 5 | public class Solution { 6 | public int findSpecialInteger(int[] arr) { 7 | int quarter = arr.length / 4; 8 | for (int i = 0; i < arr.length - quarter; i++) { 9 | if (arr[i] == arr[i + quarter]) { 10 | return arr[i]; 11 | } 12 | } 13 | return -1; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g1301_1400/s1341_movie_rating/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #Database #2023_08_16_Time_2515_ms_(78.94%)_Space_0B_(100.00%) 3 | (SELECT name results 4 | FROM Users as U, MovieRating as MR 5 | WHERE U.user_id = MR.user_id 6 | GROUP BY U.user_id 7 | ORDER BY COUNT(MR.user_id) DESC, name ASC LIMIT 1) 8 | UNION ALL 9 | (SELECT title results 10 | FROM Movies as M, MovieRating as MR 11 | WHERE M.movie_id = MR.movie_id AND created_at BETWEEN '2020-02-01' AND '2020-02-29' 12 | GROUP BY M.movie_id 13 | ORDER BY AVG(rating) DESC, title ASC LIMIT 1) 14 | -------------------------------------------------------------------------------- /src/main/java/g1401_1500/s1470_shuffle_the_array/Solution.java: -------------------------------------------------------------------------------- 1 | package g1401_1500.s1470_shuffle_the_array; 2 | 3 | // #Easy #Array #2022_03_29_Time_1_ms_(51.62%)_Space_45.5_MB_(66.97%) 4 | 5 | public class Solution { 6 | public int[] shuffle(int[] nums, int n) { 7 | int[] result = new int[nums.length]; 8 | int i = 0; 9 | int j = 0; 10 | while (i < n && j < 2 * n) { 11 | result[j] = nums[i]; 12 | result[++j] = nums[i + n]; 13 | i++; 14 | j++; 15 | } 16 | return result; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/g1801_1900/s1816_truncate_sentence/Solution.java: -------------------------------------------------------------------------------- 1 | package g1801_1900.s1816_truncate_sentence; 2 | 3 | // #Easy #Array #String #2022_05_03_Time_2_ms_(65.71%)_Space_42.9_MB_(30.34%) 4 | 5 | public class Solution { 6 | public String truncateSentence(String s, int k) { 7 | String[] words = s.split(" "); 8 | StringBuilder sb = new StringBuilder(); 9 | for (int i = 0; i < k; i++) { 10 | sb.append(words[i]); 11 | sb.append(" "); 12 | } 13 | return sb.substring(0, sb.toString().length() - 1); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g1801_1900/s1835_find_xor_sum_of_all_pairs_bitwise_and/Solution.java: -------------------------------------------------------------------------------- 1 | package g1801_1900.s1835_find_xor_sum_of_all_pairs_bitwise_and; 2 | 3 | // #Hard #Array #Math #Bit_Manipulation #2022_05_07_Time_1_ms_(100.00%)_Space_57.9_MB_(83.33%) 4 | 5 | public class Solution { 6 | public int getXORSum(int[] arr1, int[] arr2) { 7 | int xor1 = 0; 8 | int xor2 = 0; 9 | for (int i : arr1) { 10 | xor1 ^= i; 11 | } 12 | for (int j : arr2) { 13 | xor2 ^= j; 14 | } 15 | return xor1 & xor2; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/g3501_3600/s3502_minimum_cost_to_reach_every_position/Solution.java: -------------------------------------------------------------------------------- 1 | package g3501_3600.s3502_minimum_cost_to_reach_every_position; 2 | 3 | // #Easy #Array #2025_04_01_Time_1_ms_(97.59%)_Space_44.92_MB_(69.12%) 4 | 5 | public class Solution { 6 | public int[] minCosts(int[] cost) { 7 | int min = cost[0]; 8 | int[] ans = new int[cost.length]; 9 | ans[0] = min; 10 | for (int i = 1; i < cost.length; i++) { 11 | min = Math.min(min, cost[i]); 12 | ans[i] = min; 13 | } 14 | return ans; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/g3601_3700/s3657_find_loyal_customers/script.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | # #Medium #Database #2025_08_25_Time_297_ms_(100.00%)_Space_0.0_MB_(100.00%) 3 | SELECT 4 | customer_id 5 | FROM 6 | customer_transactions 7 | GROUP BY 8 | customer_id 9 | HAVING 10 | COUNT(CASE WHEN transaction_type = 'purchase' THEN 1 END) > 2 11 | AND TIMESTAMPDIFF(DAY, MIN(transaction_date), MAX(transaction_date)) > 29 12 | AND (COUNT(CASE WHEN transaction_type = 'refund' THEN 1 END) * 1.0 / COUNT(*)) < 0.2 13 | ORDER BY 14 | customer_id ASC; 15 | -------------------------------------------------------------------------------- /src/test/java/g0301_0400/s0367_valid_perfect_square/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0301_0400.s0367_valid_perfect_square; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void isPerfectSquare() { 11 | assertThat(new Solution().isPerfectSquare(16), equalTo(true)); 12 | } 13 | 14 | @Test 15 | void isPerfectSquare2() { 16 | assertThat(new Solution().isPerfectSquare(14), equalTo(false)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0501_0600/s0507_perfect_number/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0501_0600.s0507_perfect_number; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void checkPerfectNumber() { 11 | assertThat(new Solution().checkPerfectNumber(28), equalTo(true)); 12 | } 13 | 14 | @Test 15 | void checkPerfectNumber2() { 16 | assertThat(new Solution().checkPerfectNumber(7), equalTo(false)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0501_0600/s0520_detect_capital/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0501_0600.s0520_detect_capital; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void detectCapitalUse() { 11 | assertThat(new Solution().detectCapitalUse("USA"), equalTo(true)); 12 | } 13 | 14 | @Test 15 | void detectCapitalUse2() { 16 | assertThat(new Solution().detectCapitalUse("FlaG"), equalTo(false)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0601_0700/s0647_palindromic_substrings/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0601_0700.s0647_palindromic_substrings; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void countSubstrings() { 11 | assertThat(new Solution().countSubstrings("abc"), equalTo(3)); 12 | } 13 | 14 | @Test 15 | void countSubstrings2() { 16 | assertThat(new Solution().countSubstrings("aaa"), equalTo(6)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0601_0700/s0679_24_game/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0601_0700.s0679_24_game; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void judgePoint24() { 11 | assertThat(new Solution().judgePoint24(new int[] {4, 1, 8, 7}), equalTo(true)); 12 | } 13 | 14 | @Test 15 | void judgePoint242() { 16 | assertThat(new Solution().judgePoint24(new int[] {1, 2, 1, 2}), equalTo(false)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0701_0800/s0796_rotate_string/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0701_0800.s0796_rotate_string; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void rotateString() { 11 | assertThat(new Solution().rotateString("abcde", "cdeab"), equalTo(true)); 12 | } 13 | 14 | @Test 15 | void rotateString2() { 16 | assertThat(new Solution().rotateString("abcde", "abced"), equalTo(false)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0801_0900/s0878_nth_magical_number/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0801_0900.s0878_nth_magical_number; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void nthMagicalNumber() { 11 | assertThat(new Solution().nthMagicalNumber(1, 2, 3), equalTo(2)); 12 | } 13 | 14 | @Test 15 | void nthMagicalNumber2() { 16 | assertThat(new Solution().nthMagicalNumber(4, 2, 3), equalTo(6)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g1301_1400/s1399_count_largest_group/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g1301_1400.s1399_count_largest_group; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void countLargestGroup() { 11 | assertThat(new Solution().countLargestGroup(13), equalTo(4)); 12 | } 13 | 14 | @Test 15 | void countLargestGroup2() { 16 | assertThat(new Solution().countLargestGroup(13), equalTo(4)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g1401_1500/s1411_number_of_ways_to_paint_n_3_grid/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g1401_1500.s1411_number_of_ways_to_paint_n_3_grid; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void numOfWays() { 11 | assertThat(new Solution().numOfWays(1), equalTo(12)); 12 | } 13 | 14 | @Test 15 | void numOfWays2() { 16 | assertThat(new Solution().numOfWays(5000), equalTo(30228214)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g1801_1900/s1881_maximum_value_after_insertion/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g1801_1900.s1881_maximum_value_after_insertion; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void maxValue() { 11 | assertThat(new Solution().maxValue("99", 9), equalTo("999")); 12 | } 13 | 14 | @Test 15 | void maxValue2() { 16 | assertThat(new Solution().maxValue("-13", 2), equalTo("-123")); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g1801_1900/s1884_egg_drop_with_2_eggs_and_n_floors/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g1801_1900.s1884_egg_drop_with_2_eggs_and_n_floors; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void twoEggDrop() { 11 | assertThat(new Solution().twoEggDrop(2), equalTo(2)); 12 | } 13 | 14 | @Test 15 | void twoEggDrop2() { 16 | assertThat(new Solution().twoEggDrop(100), equalTo(14)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g2201_2300/s2293_min_max_game/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g2201_2300.s2293_min_max_game; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void minMaxGame() { 11 | assertThat(new Solution().minMaxGame(new int[] {1, 3, 5, 2, 4, 8, 2, 2}), equalTo(1)); 12 | } 13 | 14 | @Test 15 | void minMaxGame2() { 16 | assertThat(new Solution().minMaxGame(new int[] {3}), equalTo(3)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g2401_2500/s2427_number_of_common_factors/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g2401_2500.s2427_number_of_common_factors; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void commonFactors() { 11 | assertThat(new Solution().commonFactors(12, 6), equalTo(4)); 12 | } 13 | 14 | @Test 15 | void commonFactors2() { 16 | assertThat(new Solution().commonFactors(25, 30), equalTo(2)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g2501_2600/s2543_check_if_point_is_reachable/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g2501_2600.s2543_check_if_point_is_reachable; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void isReachable() { 11 | assertThat(new Solution().isReachable(6, 9), equalTo(false)); 12 | } 13 | 14 | @Test 15 | void isReachable2() { 16 | assertThat(new Solution().isReachable(4, 7), equalTo(true)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g2601_2700/s2681_power_of_heroes/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g2601_2700.s2681_power_of_heroes; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void sumOfPower() { 11 | assertThat(new Solution().sumOfPower(new int[] {2, 1, 4}), equalTo(141)); 12 | } 13 | 14 | @Test 15 | void sumOfPower2() { 16 | assertThat(new Solution().sumOfPower(new int[] {1, 1, 1}), equalTo(7)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g2701_2800/s2706_buy_two_chocolates/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g2701_2800.s2706_buy_two_chocolates; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void buyChoco() { 11 | assertThat(new Solution().buyChoco(new int[] {1, 2, 2}, 3), equalTo(0)); 12 | } 13 | 14 | @Test 15 | void buyChoco2() { 16 | assertThat(new Solution().buyChoco(new int[] {3, 2, 3}, 3), equalTo(3)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g3601_3700/s3699_number_of_zigzag_arrays_i/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g3601_3700.s3699_number_of_zigzag_arrays_i; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void zigZagArrays() { 11 | assertThat(new Solution().zigZagArrays(3, 4, 5), equalTo(2)); 12 | } 13 | 14 | @Test 15 | void zigZagArrays2() { 16 | assertThat(new Solution().zigZagArrays(3, 1, 3), equalTo(10)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g3701_3800/s3707_equal_score_substrings/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g3701_3800.s3707_equal_score_substrings; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void scoreBalance() { 11 | assertThat(new Solution().scoreBalance("adcb"), equalTo(true)); 12 | } 13 | 14 | @Test 15 | void scoreBalance2() { 16 | assertThat(new Solution().scoreBalance("bace"), equalTo(false)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/g0001_0100/s0067_add_binary/readme.md: -------------------------------------------------------------------------------- 1 | 67\. Add Binary 2 | 3 | Easy 4 | 5 | Given two binary strings `a` and `b`, return _their sum as a binary string_. 6 | 7 | **Example 1:** 8 | 9 | **Input:** a = "11", b = "1" 10 | 11 | **Output:** "100" 12 | 13 | **Example 2:** 14 | 15 | **Input:** a = "1010", b = "1011" 16 | 17 | **Output:** "10101" 18 | 19 | **Constraints:** 20 | 21 | * 1 <= a.length, b.length <= 104 22 | * `a` and `b` consist only of `'0'` or `'1'` characters. 23 | * Each string does not contain leading zeros except for the zero itself. -------------------------------------------------------------------------------- /src/main/java/g0301_0400/s0326_power_of_three/Solution.java: -------------------------------------------------------------------------------- 1 | package g0301_0400.s0326_power_of_three; 2 | 3 | // #Easy #Math #Recursion #2022_07_09_Time_18_ms_(85.35%)_Space_47.9_MB_(14.68%) 4 | 5 | public class Solution { 6 | // regular method that has a loop 7 | public boolean isPowerOfThree(int n) { 8 | if (n < 3 && n != 1) { 9 | return false; 10 | } 11 | while (n != 1) { 12 | if (n % 3 != 0) { 13 | return false; 14 | } 15 | n /= 3; 16 | } 17 | return true; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/g0301_0400/s0357_count_numbers_with_unique_digits/readme.md: -------------------------------------------------------------------------------- 1 | 357\. Count Numbers with Unique Digits 2 | 3 | Medium 4 | 5 | Given an integer `n`, return the count of all numbers with unique digits, `x`, where 0 <= x < 10n. 6 | 7 | **Example 1:** 8 | 9 | **Input:** n = 2 10 | 11 | **Output:** 91 12 | 13 | **Explanation:** The answer should be the total numbers in the range of 0 ≤ x < 100, excluding 11,22,33,44,55,66,77,88,99 14 | 15 | **Example 2:** 16 | 17 | **Input:** n = 0 18 | 19 | **Output:** 1 20 | 21 | **Constraints:** 22 | 23 | * `0 <= n <= 8` -------------------------------------------------------------------------------- /src/main/java/g0801_0900/s0858_mirror_reflection/Solution.java: -------------------------------------------------------------------------------- 1 | package g0801_0900.s0858_mirror_reflection; 2 | 3 | // #Medium #Math #Geometry #2022_03_27_Time_0_ms_(100.00%)_Space_40.8_MB_(64.41%) 4 | 5 | public class Solution { 6 | public int mirrorReflection(int p, int q) { 7 | while (p % 2 == 0 && q % 2 == 0) { 8 | p /= 2; 9 | q /= 2; 10 | } 11 | if (p % 2 == 0) { 12 | return 2; 13 | } else if (q % 2 == 0) { 14 | return 0; 15 | } else { 16 | return 1; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/g1401_1500/s1413_minimum_value_to_get_positive_step_by_step_sum/Solution.java: -------------------------------------------------------------------------------- 1 | package g1401_1500.s1413_minimum_value_to_get_positive_step_by_step_sum; 2 | 3 | // #Easy #Array #Prefix_Sum #2022_03_26_Time_0_ms_(100.00%)_Space_41.7_MB_(40.67%) 4 | 5 | public class Solution { 6 | public int minStartValue(int[] nums) { 7 | int min = Integer.MAX_VALUE; 8 | int sum = 0; 9 | for (int num : nums) { 10 | sum += num; 11 | min = Math.min(sum, min); 12 | } 13 | return min > 0 ? 1 : Math.abs(min) + 1; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g1401_1500/s1486_xor_operation_in_an_array/Solution.java: -------------------------------------------------------------------------------- 1 | package g1401_1500.s1486_xor_operation_in_an_array; 2 | 3 | // #Easy #Math #Bit_Manipulation #2022_04_05_Time_0_ms_(100.00%)_Space_40.7_MB_(58.44%) 4 | 5 | public class Solution { 6 | public int xorOperation(int n, int start) { 7 | int[] nums = new int[n]; 8 | for (int i = 0; i < n; i++) { 9 | nums[i] = start + 2 * i; 10 | } 11 | int result = 0; 12 | for (int num : nums) { 13 | result ^= num; 14 | } 15 | return result; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/g1501_1600/s1529_bulb_switcher_iv/Solution.java: -------------------------------------------------------------------------------- 1 | package g1501_1600.s1529_bulb_switcher_iv; 2 | 3 | // #Medium #String #Greedy #2022_04_09_Time_6_ms_(89.67%)_Space_48.3_MB_(7.02%) 4 | 5 | public class Solution { 6 | public int minFlips(String target) { 7 | int flipCount = target.charAt(0) - 48; 8 | char prev = target.charAt(0); 9 | for (char ch : target.toCharArray()) { 10 | if (ch != prev) { 11 | flipCount++; 12 | prev = ch; 13 | } 14 | } 15 | return flipCount; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/g1501_1600/s1588_sum_of_all_odd_length_subarrays/Solution.java: -------------------------------------------------------------------------------- 1 | package g1501_1600.s1588_sum_of_all_odd_length_subarrays; 2 | 3 | // #Easy #Array #Math #Prefix_Sum #Programming_Skills_I_Day_6_Array 4 | // #2022_04_11_Time_0_ms_(100.00%)_Space_41.9_MB_(46.97%) 5 | 6 | public class Solution { 7 | public int sumOddLengthSubarrays(int[] arr) { 8 | int len = arr.length; 9 | int sum = 0; 10 | for (int i = 0; i <= len - 1; i++) { 11 | sum = sum + (((i + 1) * (len - i) + 1) / 2) * arr[i]; 12 | } 13 | return sum; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/g1801_1900/s1832_check_if_the_sentence_is_pangram/Solution.java: -------------------------------------------------------------------------------- 1 | package g1801_1900.s1832_check_if_the_sentence_is_pangram; 2 | 3 | // #Easy #String #Hash_Table #2022_05_07_Time_3_ms_(41.29%)_Space_42.1_MB_(54.65%) 4 | 5 | import java.util.HashSet; 6 | import java.util.Set; 7 | 8 | public class Solution { 9 | public boolean checkIfPangram(String sentence) { 10 | Set alphabet = new HashSet<>(); 11 | for (char c : sentence.toCharArray()) { 12 | alphabet.add(c); 13 | } 14 | return alphabet.size() == 26; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/g2301_2400/s2348_number_of_zero_filled_subarrays/Solution.java: -------------------------------------------------------------------------------- 1 | package g2301_2400.s2348_number_of_zero_filled_subarrays; 2 | 3 | // #Medium #Array #Math #2022_07_30_Time_3_ms_(99.90%)_Space_59.8_MB_(95.67%) 4 | 5 | public class Solution { 6 | public long zeroFilledSubarray(int[] nums) { 7 | long cnt = 0L; 8 | long local = 0L; 9 | for (int n : nums) { 10 | if (n == 0) { 11 | cnt += ++local; 12 | } else { 13 | local = 0; 14 | } 15 | } 16 | return cnt; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/g2501_2600/s2520_count_the_digits_that_divide_a_number/Solution.java: -------------------------------------------------------------------------------- 1 | package g2501_2600.s2520_count_the_digits_that_divide_a_number; 2 | 3 | // #Easy #Math #2023_04_18_Time_0_ms_(100.00%)_Space_39.3_MB_(62.57%) 4 | 5 | public class Solution { 6 | public int countDigits(int num) { 7 | int a = num; 8 | int count = 0; 9 | while (a > 0) { 10 | int r = a % 10; 11 | if (r != 0 && num % r == 0) { 12 | count++; 13 | } 14 | a /= 10; 15 | } 16 | return count; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/g2601_2700/s2618_check_if_object_instance_of_class/solution.ts: -------------------------------------------------------------------------------- 1 | // #Medium #2023_08_30_Time_82_ms_(99.55%)_Space_52.1_MB_(79.46%) 2 | 3 | function checkIfInstanceOf(obj: any, classFunction: any): boolean { 4 | if (obj === null || obj === undefined || typeof classFunction !== 'function') return false 5 | 6 | let proto = Object.getPrototypeOf(obj) 7 | while (proto !== null) { 8 | if (proto === classFunction.prototype) return true 9 | proto = Object.getPrototypeOf(proto) 10 | } 11 | return false 12 | } 13 | 14 | export { checkIfInstanceOf } 15 | -------------------------------------------------------------------------------- /src/main/java/g3101_3200/s3131_find_the_integer_added_to_array_i/Solution.java: -------------------------------------------------------------------------------- 1 | package g3101_3200.s3131_find_the_integer_added_to_array_i; 2 | 3 | // #Easy #Array #2024_05_02_Time_0_ms_(100.00%)_Space_43_MB_(75.29%) 4 | 5 | public class Solution { 6 | public int addedInteger(int[] nums1, int[] nums2) { 7 | int n1 = nums1.length; 8 | int s1 = 0; 9 | int s2 = 0; 10 | for (int i : nums1) { 11 | s1 += i; 12 | } 13 | for (int i : nums2) { 14 | s2 += i; 15 | } 16 | return (s2 - s1) / n1; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0301_0400/s0307_range_sum_query_mutable/NumArrayTest.java: -------------------------------------------------------------------------------- 1 | package g0301_0400.s0307_range_sum_query_mutable; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class NumArrayTest { 9 | @Test 10 | void numArray() { 11 | NumArray numArray = new NumArray(new int[] {1, 3, 5}); 12 | assertThat(numArray.sumRange(0, 2), equalTo(9)); 13 | numArray.update(1, 2); 14 | assertThat(numArray.sumRange(0, 2), equalTo(8)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/g0301_0400/s0392_is_subsequence/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0301_0400.s0392_is_subsequence; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void isSubsequence() { 11 | assertThat(new Solution().isSubsequence("abc", "ahbgdc"), equalTo(true)); 12 | } 13 | 14 | @Test 15 | void isSubsequence2() { 16 | assertThat(new Solution().isSubsequence("axc", "ahbgdc"), equalTo(false)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/g0501_0600/s0525_contiguous_array/SolutionTest.java: -------------------------------------------------------------------------------- 1 | package g0501_0600.s0525_contiguous_array; 2 | 3 | import static org.hamcrest.CoreMatchers.equalTo; 4 | import static org.hamcrest.MatcherAssert.assertThat; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SolutionTest { 9 | @Test 10 | void findMaxLength() { 11 | assertThat(new Solution().findMaxLength(new int[] {0, 1}), equalTo(2)); 12 | } 13 | 14 | @Test 15 | void findMaxLength2() { 16 | assertThat(new Solution().findMaxLength(new int[] {0, 1, 0}), equalTo(2)); 17 | } 18 | } 19 | --------------------------------------------------------------------------------