├── .github └── workflows │ ├── language_statistics.yml │ └── leetcode_ranking.yml ├── .gitignore ├── Algorithms ├── 1002_Find_Common_Characters │ └── solution.c ├── 1004_Max_Consecutive_Ones_III │ └── Solution.java ├── 1007_Minimum_Domino_Rotations_For_Equal_Row │ └── Solution.kt ├── 1008_Construct_Binary_Search_Tree_from_Preorder_Traversal │ ├── solution.go │ └── solution.rb ├── 1009_Complement_of_Base_10_Integer │ └── Solution.scala ├── 100_Same_Tree │ └── solution.py ├── 1010_Pairs_of_Songs_With_Total_Durations_Divisible_by_60 │ └── solution.go ├── 1019_Next_Greater_Node_In_Linked_List │ └── Solution.kt ├── 101_Symmetric_Tree │ └── solution.py ├── 1020_Number_of_Enclaves │ └── Solution.kt ├── 1021_Remove_Outermost_Parentheses │ └── Solution.kt ├── 1022_Sum_of_Root_To_Leaf_Binary_Numbers │ └── Solution.kt ├── 1023_Camelcase_Matching │ └── Solution.kt ├── 1026_Maximum_Difference_Between_Node_and_Ancestor │ └── solution.go ├── 1028_Recover_a_Tree_From_Preorder_Traversal │ └── solution.py ├── 1029_Two_City_Scheduling │ └── solution.go ├── 102_Binary_Tree_Level_Order_Traversal │ └── Solution.cpp ├── 1030_Matrix_Cells_in_Distance_Order │ └── Solution.kt ├── 1035_Uncrossed_Lines │ └── solution.go ├── 1038_Binary_Search_Tree_to_Greater_Sum_Tree │ └── Solution.cpp ├── 103_Binary_Tree_Zigzag_Level_Order_Traversal │ └── Solution.cpp ├── 1041_Robot_Bounded_In_Circle │ └── Solution.kt ├── 1046_Last_Stone_Weight │ └── solution.py ├── 1047_Remove_All_Adjacent_Duplicates_In_String │ └── solution.c ├── 104_Maximum_Depth_of_Binary_Tree │ └── solution.py ├── 1051_Height_Checker │ └── Solution.cpp ├── 105_Construct_Binary_Tree_from_Preorder_and_Inorder_Traversal │ └── Solution.java ├── 1060_Missing_Element_in_Sorted_Array │ └── Solution.scala ├── 106_Construct_Binary_Tree_from_Inorder_and_Postorder_Traversal │ └── Solution.cpp ├── 1078_Occurrences_After_Bigram │ └── Solution.kt ├── 1079_Letter_Tile_Possibilities │ └── Solution.kt ├── 107_Binary_Tree_Level_Order_Traversal_II │ └── solution.py ├── 1081_Smallest_Subsequence_of_Distinct_Characters │ └── Solution.java ├── 1086_High_Five │ └── Solution.scala ├── 108_Convert_Sorted_Array_to_Binary_Search_Tree │ └── solution.py ├── 1090_Largest_Values_From_Labels │ └── Solution.kt ├── 1091_Shortest_Path_in_Binary_Matrix │ └── Solution.scala ├── 109_Convert_Sorted_List_to_Binary_Search_Tree │ └── solution.go ├── 10_Regular_Expression_Matching │ └── Solution.kt ├── 1104_Path_In_Zigzag_Labelled_Binary_Tree │ └── Solution.java ├── 1108_Defanging_an_IP_Address │ └── solution.rb ├── 1109_Corporate_Flight_Bookings │ └── Solution.kt ├── 110_Balanced_Binary_Tree │ └── solution.py ├── 1110_Delete_Nodes_And_Return_Forest │ └── Solution.scala ├── 1119_Remove_Vowels_from_a_String │ └── Solution.scala ├── 111_Minimum_Depth_of_Binary_Tree │ └── solution.py ├── 1120_Maximum_Average_Subtree │ └── Solution.java ├── 1122_Relative_Sort_Array │ └── Solution.kt ├── 1123_Lowest_Common_Ancestor_of_Deepest_Leaves │ └── Solution.kt ├── 1129_Shortest_Path_with_Alternating_Colors │ └── Solution.kt ├── 112_Path_Sum │ └── solution.py ├── 1130_Minimum_Cost_Tree_From_Leaf_Values │ └── Solution.kt ├── 1133_Largest_Unique_Number │ └── Solution.java ├── 1135_Connecting_Cities_With_Minimum_Cost │ └── Solution.java ├── 1136_Parallel_Courses │ └── Solution.java ├── 1138_Alphabet_Board_Path │ └── Solution.kt ├── 113_Path_Sum_II │ └── solution.go ├── 1143_Longest_Common_Subsequence │ └── Solution.java ├── 114_Flatten_Binary_Tree_to_Linked_List │ └── solution.go ├── 1151_Minimum_Swaps_to_Group_All_1s_Together │ └── Solution.java ├── 1152_Analyze_User_Website_Visit_Pattern │ └── Solution.scala ├── 1154_Day_of_the_Year │ └── Solution.kt ├── 1155_Number_of_Dice_Rolls_With_Target_Sum │ └── Solution.kt ├── 1160_Find_Words_That_Can_Be_Formed_by_Character │ └── Solution.kt ├── 1161_Maximum_Level_Sum_of_a_Binary_Tree │ └── Solution.kt ├── 1162_As_Far_from_Land_as_Possible │ └── Solution.kt ├── 1165_Single-Row_Keyboard │ └── Solution.scala ├── 1167_Minimum_Cost_to_Connect_Sticks │ └── Solution.scala ├── 1169_Invalid_Transactions │ └── Solution.kt ├── 116_Populating_Next_Right_Pointers_in_Each_Node │ └── Solution.kt ├── 117_Populating_Next_Right_Pointers_in_Each_Node_II │ └── Solution.kt ├── 1184_Distance_Between_Bus_Stops │ └── Solution.kt ├── 1189_Maximum_Number_of_Balloons │ └── solution.c ├── 118_Pascal's_Triangle │ └── solution.py ├── 1190_Reverse_Substrings_Between_Each_Pair_of_Parentheses │ ├── Solution.kt │ └── solution.py ├── 1192_Critical_Connections_in_a_Network │ └── solution.py ├── 1198_Find_Smallest_Common_Element_in_All_Rows │ └── Solution.kt ├── 119_Pascal's_Triangle_II │ └── solution.py ├── 11_Container_With_Most_Water │ ├── Solution.kt │ └── Solution.py ├── 1200_Minimum_Absolute_Difference │ └── Solution.kt ├── 1202_Smallest_String_With_Swaps │ └── Solution.kt ├── 1207_Unique_Number_of_Occurrences │ └── Solution.cpp ├── 1209_Remove_All_Adjacent_Duplicates_in_String_II │ └── solution.py ├── 120_Triangle │ └── solution.py ├── 1213_Intersection_of_Three_Sorted_Arrays │ └── Solution.kt ├── 1217_Minimum_Cost_to_Move_Chips_to_The_Same_Position │ └── Solution.kt ├── 1219_Path_with_Maximum_Gold │ └── Solution.kt ├── 121_Best_Time_to_Buy_and_Sell_Stock │ └── solution.py ├── 1221_Split_a_String_in_Balanced_Strings │ └── Solution.cpp ├── 1222_Queens_That_Can_Attack_the_King │ └── solution.js ├── 1228_Missing_Number_In_Arithmetic_Progression │ └── Solution.java ├── 1229_Meeting_Scheduler │ └── Solution.java ├── 122_Best_Time_to_Buy_and_Sell_Stock_II │ └── solution.py ├── 1232_Check_If_It_Is_a_Straight_Line │ └── solution.py ├── 1233_Remove_Sub-Folders_from_the_Filesystem │ └── Solution.kt ├── 1235_Maximum_Profit_in_Job_Scheduling │ └── Solution.java ├── 1239_Maximum_Length_of_a_Concatenated_String_with_Unique_Characters │ └── Solution.kt ├── 1244_Design_A_Leaderboard │ └── Leaderboard.scala ├── 1249_Minimum_Remove_to_Make_Valid_Parentheses │ ├── Solution.java │ ├── Solution.scala │ └── solution.py ├── 1252_Cells_with_Odd_Values_in_a_Matrix │ └── solution.go ├── 1254_Number_of_Closed_Islands │ └── Solution.java ├── 1255_Maximum_Score_Words_Formed_by_Letters │ └── Solution.kt ├── 125_Valid_Palindrome │ └── solution.py ├── 1260_Shift_2D_Grid │ └── Solution.kt ├── 1261_Find_Elements_in_a_Contaminated_Binary_Tree │ └── Solution.java ├── 1265_Print_Immutable_Linked_List_in_Reverse │ └── solution.go ├── 1267_Count_Servers_that_Communicate │ └── Solution.cpp ├── 1268_Search_Suggestions_System │ └── Solution.java ├── 126_Word_Ladder_II │ └── solution.py ├── 1277_Count_Square_Submatrices_with_All_Ones │ └── solution.go ├── 127_Word_Ladder │ └── Solution.kt ├── 1281_Subtract_the_Product_and_Sum_of_Digits_of_an_Integer │ └── Solution.cpp ├── 1282_Group_the_People_Given_the_Group_Size_They_Belong_To │ └── solution.py ├── 1283_Find_the_Smallest_Divisor_Given_a_Threshold │ └── Solution.kt ├── 1286_Iterator_for_Combination │ └── CombinationIterator.kt ├── 1287_Element_Appearing_More_Than_25%_In_Sorted_Array │ └── Solution.kt ├── 1288_Remove_Covered_Intervals │ └── Solution.scala ├── 128_Longest_Consecutive_Sequence │ └── Solution.scala ├── 1290_Convert_Binary_Number_in_a_Linked_List_to_Integer │ └── Solution.cpp ├── 1291_Sequential_Digits │ └── Solution.kt ├── 1293_Shortest_Path_in_a_Grid_with_Obstacles_Elimination │ └── Solution.java ├── 1295_Find_Numbers_with_Even_Number_of_Digits │ └── Solution.cpp ├── 1296_Divide_Array_in_Sets_of_K_Consecutive_Numbers │ └── Solution.java ├── 1299_Replace_Elements_with_Greatest_Element_on_Right_Side │ └── Solution.cpp ├── 129_Sum_Root_to_Leaf_Numbers │ └── Solution.kt ├── 12_Integer_to_Roman │ └── Solution.kt ├── 1302_Deepest_Leaves_Sum │ └── Solution.cpp ├── 1304_Find_N_Unique_Integers_Sum_up_to_Zero │ └── Solution.cpp ├── 1305_All_Elements_in_Two_Binary_Search_Trees │ └── Solution.cpp ├── 1306_Jump_Game_III │ └── Solution.kt ├── 1309_Decrypt_String_from_Alphabet_to_Integer_Mapping │ └── solution.py ├── 130_Surrounded_Regions │ └── solution.go ├── 1313_Decompress_Run-Length_Encoded_List │ └── Solution.cpp ├── 1314_Matrix_Block_Sum │ └── Solution.scala ├── 1315_Sum_of_Nodes_with_Even-Valued_Grandparent │ └── Solution.cpp ├── 1319_Number_of_Operations_to_Make_Network_Connected │ └── Solution.kt ├── 131_Palindrome_Partitioning │ └── Solution.kt ├── 1323_Maximum_69_Number │ └── Solution.cpp ├── 1324_Print_Words_Vertically │ └── Solution.kt ├── 1325_Delete_Leaves_With_a_Given_Value │ └── Solution.java ├── 1328_Break_a_Palindrome │ └── Solution.kt ├── 1329_Sort_the_Matrix_Diagonally │ └── Solution.cpp ├── 1331_Rank_Transform_of_an_Array │ └── Solution.kt ├── 1332_Remove_Palindromic_Subsequences │ └── solution.go ├── 1333_Filter_Restaurants_by_Vegan-Friendly,_Price_and_Distance │ └── Solution.scala ├── 1335_Minimum_Difficulty_of_a_Job_Schedule │ └── Solution.kt ├── 1337_The_K_Weakest_Rows_in_a_Matrix │ └── Solution.scala ├── 1338_Reduce_Array_Size_to_The_Half │ └── Solution.kt ├── 1339_Maximum_Product_of_Splitted_Binary_Tree │ └── Solution.kt ├── 133_Clone_Graph │ └── Solution.kt ├── 1342_Number_of_Steps_to_Reduce_a_Number_to_Zero │ └── Solution.cpp ├── 1343_Number_of_Sub-arrays_of_Size_K_and_Average_Greater_than_or_Equal_to_Threshold │ └── Solution.kt ├── 1344_Angle_Between_Hands_of_a_Clock │ └── Solution.kt ├── 1346_Check_If_N_and_Its_Double_Exist │ └── Solution.kt ├── 1347_Minimum_Number_of_Steps_to_Make_Two_Strings_Anagram │ └── Solution.java ├── 134_Gas_Station │ └── Solution.kt ├── 1351_Count_Negative_Numbers_in_a_Sorted_Matrix │ └── Solution.cpp ├── 1354_Construct_Target_Array_With_Multiple_Sums │ └── Solution.java ├── 1356_Sort_Integers_by_The_Number_of_1_Bits │ └── solution.js ├── 1357_Apply_Discount_Every_n_Orders │ └── Solution.kt ├── 1358_Number_of_Substrings_Containing_All_Three_Characters │ └── Solution.kt ├── 135_Candy │ └── Solution.kt ├── 1365_How_Many_Numbers_Are_Smaller_Than_the_Current_Number │ └── Solution.cpp ├── 1366_Rank_Teams_by_Votes │ └── Solution.kt ├── 1367_Linked_List_in_Binary_Tree │ └── Solution.kt ├── 136_Single_Number │ ├── Solution.java │ ├── solution.py │ └── solution.rb ├── 1370_Increasing_Decreasing_String │ └── Solution.kt ├── 1372_Longest_ZigZag_Path_in_a_Binary_Tree │ └── Solution.kt ├── 1374_Generate_a_String_With_Characters_That_Have_Odd_Counts │ └── solution.c ├── 1375_Number_of_Times_Binary_String_Is_Prefix-Aligned │ └── Solution.kt ├── 1376_Time_Needed_to_Inform_All_Employees │ └── Solution.kt ├── 1379_Find_a_Corresponding_Node_of_a_Binary_Tree_in_a_Clone_of_That_Tree │ └── Solution.cpp ├── 137_Single_Number_II │ └── Solution.java ├── 1380_Lucky_Numbers_in_a_Matrix │ └── Solution.kt ├── 1381_Design_a_Stack_With_Increment_Operation │ ├── CustomStack.kt │ └── CustomStack.scala ├── 1382_Balance_a_Binary_Search_Tree │ └── Solution.kt ├── 1383_Maximum_Performance_of_a_Team │ └── Solution.kt ├── 1385_Find_the_Distance_Value_Between_Two_Arrays │ └── Solution.kt ├── 1387_Sort_Integers_by_The_Power_Value │ └── Solution.kt ├── 1389_Create_Target_Array_in_the_Given_Order │ └── solution.go ├── 138_Copy_List_with_Random_Pointer │ └── Solution.kt ├── 1394_Find_Lucky_Integer_in_an_Array │ └── Solution.kt ├── 1395_Count_Number_of_Teams │ └── solution.go ├── 1396_Design_Underground_System │ └── UndergroundSystem.scala ├── 1399_Count_Largest_Group │ └── Solution.kt ├── 139_Word_Break │ └── solution.go ├── 13_Roman_to_Integer │ └── solution.c ├── 1402_Reducing_Dishes │ └── Solution.java ├── 1403_Minimum_Subsequence_in_Non-Increasing_Order │ └── Solution.kt ├── 1405_Longest_Happy_String │ └── Solution.kt ├── 1408_String_Matching_in_an_Array │ └── Solution.kt ├── 1409_Queries_on_a_Permutation_With_Key │ └── Solution.scala ├── 1410_HTML_Entity_Parser │ └── Solution.kt ├── 1413_Minimum_Value_to_Get_Positive_Step_by_Step_Sum │ └── Solution.kt ├── 1415_The_k-th_Lexicographical_String_of_All_Happy_Strings_of_Length_n │ └── Solution.kt ├── 1418_Display_Table_of_Food_Orders_in_a_Restaurant │ └── Solution.kt ├── 1419_Minimum_Number_of_Frogs_Croaking │ └── Solution.kt ├── 141_Linked_List_Cycle │ └── Solution.java ├── 1423_Maximum_Points_You_Can_Obtain_from_Cards │ └── Solution.java ├── 142_Linked_List_Cycle_II │ └── Solution.kt ├── 1431_Kids_With_the_Greatest_Number_of_Candies │ └── solution.go ├── 1436_Destination_City │ └── solution.go ├── 1437_Check_If_All_1s_Are_at_Least_Length_K_Places_Away │ ├── Solution.kt │ └── Solution.scala ├── 1438_Longest_Continuous_Subarray_With_Absolute_Diff_Less_Than_or_Equal_to_Limit │ └── Solution.kt ├── 143_Reorder_List │ └── Solution.scala ├── 1441_Build_an_Array_With_Stack_Operations │ └── Solution.kt ├── 1446_Consecutive_Characters │ └── Solution.kt ├── 1447_Simplified_Fractions │ └── Solution.kt ├── 1448_Count_Good_Nodes_in_Binary_Tree │ └── Solution.java ├── 144_Binary_Tree_Preorder_Traversal │ └── Solution.java ├── 1450_Number_of_Students_Doing_Homework_at_a_Given_Time │ └── solution.go ├── 1451_Rearrange_Words_in_a_Sentence │ └── Solution.kt ├── 1452_People_Whose_List_of_Favorite_Companies_Is_Not_a_Subset_of_Another_List │ └── Solution.kt ├── 1455_Check_If_a_Word_Occurs_As_a_Prefix_of_Any_Word_in_a_Sentence │ └── Solution.kt ├── 1457_Pseudo-Palindromic_Paths_in_a_Binary_Tree │ └── Solution.kt ├── 145_Binary_Tree_Postorder_Traversal │ └── Solution.java ├── 1460_Make_Two_Arrays_Equal_by_Reversing_Sub-arrays │ └── solution.go ├── 1461_Check_If_a_String_Contains_All_Binary_Codes_of_Size_K │ └── Solution.scala ├── 1464_Maximum_Product_of_Two_Elements_in_an_Array │ └── solution.go ├── 1465_Maximum_Area_of_a_Piece_of_Cake_After_Horizontal_and_Vertical_Cuts │ └── Solution.java ├── 1466_Reorder_Routes_to_Make_All_Paths_Lead_to_the_City_Zero │ └── Solution.kt ├── 1469_Find_All_The_Lonely_Nodes │ └── Solution.scala ├── 146_LRU_Cache │ └── LRUCache.java ├── 1470_Shuffle_the_Array │ └── solution.go ├── 1472_Design_Browser_History │ └── BrowserHistory.kt ├── 1475_Final_Prices_With_a_Special_Discount_in_a_Shop │ └── Solution.kt ├── 1476_Subrectangle_Queries │ └── SubrectangleQueries.scala ├── 1480_Running_Sum_of_1d_Array │ └── solution.go ├── 1481_Least_Number_of_Unique_Integers_after_K_Removals │ └── Solution.scala ├── 1485_Clone_Binary_Tree_With_Random_Pointer │ └── Solution.java ├── 1486_XOR_Operation_in_an_Array │ └── Solution.scala ├── 1487_Making_File_Names_Unique │ └── Solution.kt ├── 148_Sort_List │ └── Solution.kt ├── 1490_Clone_N-ary_Tree │ └── Solution.scala ├── 1491_Average_Salary_Excluding_the_Minimum_and_Maximum_Salary │ └── Solution.kt ├── 1493_Longest_Subarray_of_1's_After_Deleting_One_Element │ └── Solution.kt ├── 149_Max_Points_on_a_Line │ └── solution.js ├── 14_Longest_Common_Prefix │ └── solution.rb ├── 1502_Can_Make_Arithmetic_Progression_From_Sequence │ └── Solution.scala ├── 1506_Find_Root_of_N-Ary_Tree │ └── Solution.scala ├── 1507_Reformat_Date │ └── Solution.kt ├── 150_Evaluate_Reverse_Polish_Notation │ └── Solution.kt ├── 1512_Number_of_Good_Pairs │ ├── Solution.scala │ └── solution.go ├── 151_Reverse_Words_in_a_String │ └── Solution.kt ├── 1523_Count_Odd_Numbers_in_an_Interval_Range │ └── Solution.kt ├── 1525_Number_of_Good_Ways_to_Split_a_String │ └── solution.js ├── 1528_Shuffle_String │ └── solution.go ├── 1529_Minimum_Suffix_Flips │ └── Solution.kt ├── 152_Maximum_Product_Subarray │ └── Solution.kt ├── 1530_Number_of_Good_Leaf_Nodes_Pairs │ └── Solution.kt ├── 1531_String_Compression_II │ └── Solution.kt ├── 1534_Count_Good_Triplets │ └── solution.js ├── 1539_Kth_Missing_Positive_Number │ └── solution.rb ├── 153_Find_Minimum_in_Rotated_Sorted_Array │ └── Solution.kt ├── 1544_Make_The_String_Great │ └── Solution.kt ├── 1550_Three_Consecutive_Odds │ └── Solution.kt ├── 1551_Minimum_Operations_to_Make_Array_Equal │ └── Solution.kt ├── 1557_Minimum_Number_of_Vertices_to_Reach_All_Nodes │ └── Solution.kt ├── 1558_Minimum_Numbers_of_Function_Calls_to_Make_Target_Array │ └── Solution.kt ├── 155_Min_Stsck │ └── solution.py ├── 1561_Maximum_Number_of_Coins_You_Can_Get │ └── Solution.java ├── 1564_Put_Boxes_Into_the_Warehouse_I │ └── Solution.java ├── 1570_Dot_Product_of_Two_Sparse_Vectors │ ├── sparseVector.ts │ ├── sparse_vector.rb │ └── sparsevector.go ├── 1572_Matrix_Diagonal_Sum │ └── solution.cpp ├── 1578_Minimum_Time_to_Make_Rope_Colorful │ └── Solution.kt ├── 1583_Count_Unhappy_Friends │ └── Solution.kt ├── 1584_Min_Cost_to_Connect_All_Points │ └── Solution.kt ├── 1588_Sum_of_All_Odd_Length_Subarrays │ └── Solution.kt ├── 1597_Build_Binary_Expression_Tree_From_Infix_Expression │ ├── Solution.java │ └── solution.py ├── 1598_Crawler_Log_Folder │ └── Solution.kt ├── 15_3Sum │ ├── Solution.cpp │ └── Solution.java ├── 1603_Design_Parking_System │ └── solution.go ├── 1605_Find_Valid_Matrix_Given_Row_and_Column_Sums │ └── Solution.kt ├── 1608_Special_Array_With_X_Elements_Greater_Than_or_Equal_X │ └── Solution.kt ├── 1609_Even_Odd_Tree │ └── Solution.kt ├── 160_Intersection_of_Two_Linked_Lists │ └── Solution.java ├── 1612_Check_If_Two_Expression_Trees_are_Equivalent │ └── solution.cpp ├── 1614_Maximum_Nesting_Depth_of_the_Parentheses │ └── Solution.kt ├── 1615_Maximal_Network_Rank │ └── Solution.kt ├── 1619_Mean_of_Array_After_Removing_Some_Elements │ └── Solution.kt ├── 161_One_Edit_Distance │ └── solution.go ├── 1625_Lexicographically_Smallest_String_After_Applying_Operations │ └── Solution.kt ├── 1628_Design_an_Expression_Tree_With_Evaluate_Function │ └── Solution.java ├── 162_Find_Peak_Element │ └── solution.go ├── 1630_Arithmetic_Subarrays │ ├── Solution.java │ ├── Solution.kt │ ├── Solution.scala │ └── solution.py ├── 1631_Path_With_Minimum_Effort │ └── solution.cpp ├── 1636_Sort_Array_by_Increasing_Frequency │ └── Solution.kt ├── 1637_Widest_Vertical_Area_Between_Two_Points_Containing_No_Points │ └── Solution.kt ├── 163_Missing_Ranges │ └── Solution.java ├── 1640_Check_Array_Formation_Through_Concatenation │ └── Solution.kt ├── 1641_Count_Sorted_Vowel_Strings │ └── solution.c ├── 1642_Furthest_Building_You_Can_Reach │ └── Solution.java ├── 1646_Get_Maximum_in_Generated_Array │ └── solution.c ├── 1647_Minimum_Deletions_to_Make_Character_Frequencies_Unique │ └── Solution.kt ├── 1649_Create_Sorted_Array_through_Instructions │ └── solution.go ├── 1650_Lowest_Common_Ancestor_of_a_Binary_Tree_III │ └── Solution.java ├── 1654_Minimum_Jumps_to_Reach_Home │ └── Solution.kt ├── 1656_Design_an_Ordered_Stream │ └── OrderedStream.kt ├── 1657_Determine_if_Two_Strings_Are_Close │ └── Solution.scala ├── 1658_Minimum_Operations_to_Reduce_X_to_Zero │ └── solution.go ├── 165_Compare_Version_Numbers │ └── Solution.kt ├── 1660_Correct_a_Binary_Tree │ └── Solution.java ├── 1662_Check_If_Two_String_Arrays_are_Equivalent │ └── Solution.kt ├── 1663_Smallest_String_With_A_Given_Numeric_Value │ └── solution.c ├── 1669_Merge_In_Between_Linked_Lists │ └── Solution.kt ├── 166_Fraction_to_Recurring_Decimal │ └── Solution.kt ├── 1670_Design_Front_Middle_Back_Queue │ └── Solution.kt ├── 1672_Richest_Customer_Wealth │ └── Solution.kt ├── 1673_Find_the_Most_Competitive_Subsequence │ └── Solution.kt ├── 1675_Minimize_Deviation_in_Array │ └── Solution.kt ├── 1678_Goal_Parser_Interpretation │ └── Solution.kt ├── 1679_Max_Number_of_K-Sum_Pairs │ └── Solution.kt ├── 167_Two_Sum_II_-_Input_array_is_sorted │ └── solution.rb ├── 1680_Concatenation_of_Consecutive_Binary_Numbers │ └── solution.go ├── 1684_Count_the_Number_of_Consistent_Strings │ └── Solution.scala ├── 1685_Sum_of_Absolute_Differences_in_a_Sorted_Array │ └── Solution.kt ├── 1688_Count_of_Matches_in_Tournament │ └── solution.js ├── 1689_Partitioning_Into_Minimum_Number_Of_Deci-Binary_Numbers │ └── Solution.kt ├── 168_Excel_Sheet_Column_Title │ └── solution.rb ├── 1690_Stone_Game_VII │ └── Solution.java ├── 1694_Reformat_Phone_Number │ └── Solution.kt ├── 1695_Maximum_Erasure_Value │ └── Solution.kt ├── 1696_Jump_Game_VI │ └── Solution.java ├── 169_Majority_Element │ └── Solution.kt ├── 16_3Sum │ └── solution.js ├── 1700_Number_of_Students_Unable_to_Eat_Lunch │ └── Solution.kt ├── 1701_Average_Waiting_Time │ └── Solution.kt ├── 1704_Determine_if_String_Halves_Are_Alike │ └── Solution.java ├── 1706_Where_Will_the_Ball_Fall │ └── Solution.kt ├── 170_Two_Sum_III_-_Data_structure_design │ └── TwoSum.scala ├── 1710_Maximum_Units_on_a_Truck │ └── Solution.scala ├── 1716_Calculate_Money_in_Leetcode_Bank │ └── Solution.kt ├── 171_Excel_Sheet_Column_Number │ └── solution.rb ├── 1720_Decode_XORed_Array │ └── Solution.java ├── 1721_Swapping_Nodes_in_a_Linked_List │ └── solution.go ├── 1725_Number_Of_Rectangles_That_Can_Form_The_Largest_Square │ └── Solution.kt ├── 1726_Tuple_with_Same_Product │ └── Solution.kt ├── 172_Factorial_Trailing_Zeroes │ └── solution.rb ├── 1732_Find_the_Highest_Altitude │ └── solution.cpp ├── 1734_Decode_XORed_Permutation │ └── Solution.kt ├── 173_Binary_Search_Tree_Iterator │ └── solution.go ├── 1742_Maximum_Number_of_Balls_in_a_Box │ └── Solution.kt ├── 1743_Restore_the_Array_From_Adjacent_Pairs │ └── Solution.kt ├── 1748_Sum_of_Unique_Elements │ └── Solution.kt ├── 1753_Maximum_Score_From_Removing_Stones │ └── Solution.kt ├── 1760_Minimum_Limit_of_Balls_in_a_Bag │ └── Solution.kt ├── 1762_Buildings_With_an_Ocean_View │ └── Solution.java ├── 1763_Longest_Nice_Substring │ └── Solution.kt ├── 1768_Merge_Strings_Alternately │ └── Solution.kt ├── 1769_Minimum_Number_of_Operations_to_Move_All_Balls_to_Each_Box │ └── Solution.java ├── 1770_Maximum_Score_from_Performing_Multiplication_Operations │ └── Solution.kt ├── 1773_Count_Items_Matching_a_Rule │ └── Solution.java ├── 1779_Find_Nearest_Point_That_Has_the_Same_X_or_Y_Coordinate │ └── Solution.kt ├── 1780_Check_if_Number_is_a_Sum_of_Powers_of_Three │ └── Solution.kt ├── 1781_Sum_of_Beauty_of_All_Substrings │ └── Solution.kt ├── 1790_Check_if_One_String_Swap_Can_Make_Strings_Equal │ └── Solution.kt ├── 1791_Find_Center_of_Star_Graph │ └── Solution.java ├── 1797_Design_Authentication_Manager │ └── Solution.kt ├── 179_Largest_Number │ ├── Solution.kt │ ├── Solution.scala │ └── solution.py ├── 17_Letter_Combinations_of_a_Phone_Number │ └── Solution.kt ├── 1800_Maximum_Ascending_Subarray_Sum │ └── Solution.kt ├── 1806_Minimum_Number_of_Operations_to_Reinitialize_a_Permutation │ └── Solution.kt ├── 1807_Evaluate_the_Bracket_Pairs_of_a_String │ └── Solution.kt ├── 1812_Determine_Color_of_a_Chessboard_Square │ └── solution.cpp ├── 1816_Truncate_Sentence │ └── Solution.kt ├── 1817_Finding_the_Users_Active_Minutes │ └── Solution.java ├── 1822_Sign_of_the_Product_of_an_Array │ └── Solution.kt ├── 1823_Find_the_Winner_of_the_Circular_Game │ └── solution.js ├── 1827_Minimum_Operations_to_Make_the_Array_Increasing │ └── Solution.kt ├── 1828_Queries_on_Number_of_Points_Inside_a_Circle │ └── Solution.kt ├── 1832_Check_if_the_Sentence_Is_Pangram │ └── Solution.kt ├── 1833_Maximum_Ice_Cream_Bars │ └── Solution.java ├── 1836_Remove_Duplicates_From_an_Unsorted_Linked_List │ └── Solution.java ├── 1837_Sum_of_Digits_in_Base_K │ └── solution.js ├── 1844_Replace_All_Digits_with_Characters │ └── Solution.java ├── 1845_Seat_Reservation_Manager │ └── Solution.java ├── 1846_Maximum_Element_After_Decreasing_and_Rearranging │ └── Solution.kt ├── 1852_Distinct_Numbers_in_Each_Subarray │ └── Solution.kt ├── 1855_Maximum_Distance_Between_a_Pair_of_Values │ └── Solution.kt ├── 1859_Sorting_the_Sentence │ └── Solution.java ├── 1860_Incremental_Memory_Leak │ └── Solution.kt ├── 1861_Rotating_the_Box │ └── Solution.kt ├── 1863_Sum_of_All_Subset_XOR_Totals │ └── Solution.kt ├── 1874_Minimize_Product_Sum_of_Two_Arrays │ └── Solution.kt ├── 1876_Substrings_of_Size_Three_with_Distinct_Characters │ └── Solution.kt ├── 1877_Minimize_Maximum_Pair_Sum_in_Array │ └── Solution.kt ├── 187_Repeated_DNA_Sequences │ └── Solution.kt ├── 1880_Check_if_Word_Equals_Summation_of_Two_Words │ └── Solution.java ├── 1884_Egg_Drop_With_2_Eggs_and_N_Floors │ └── Solution.kt ├── 1886_Determine_Whether_Matrix_Can_Be_Obtained_By_Rotation │ └── Solution.kt ├── 1887_Reduction_Operations_to_Make_the_Array_Elements_Equal │ └── Solution.kt ├── 1894_Find_the_Student_that_Will_Replace_the_Chalk │ └── Solution.kt ├── 1899_Merge_Triplets_to_Form_Target_Triplet │ └── Solution.kt ├── 189_Rotate_Array │ └── solution.rb ├── 18_4Sum │ └── Solution.kt ├── 1905_Count_Sub_Islands │ └── Solution.kt ├── 190_Reverse_Bits │ └── solution.rb ├── 1910_Remove_All_Occurrences_of_a_Substring │ └── Solution.kt ├── 1913_Maximum_Product_Difference_Between_Two_Pairs │ └── Solution.java ├── 191_Number_of_1_Bits │ ├── Solution.cpp │ └── solution.rb ├── 1920_Build_Array_from_Permutation │ └── Solution.kt ├── 1925_Count_Square_Sum_Triples │ └── Solution.kt ├── 1926_Nearest_Exit_from_Entrance_in_Maze │ └── Solution.kt ├── 1929_Concatenation_of_Array │ └── Solution.kt ├── 1935_Maximum_Number_of_Words_You_Can_Type │ └── Solution.kt ├── 1941_Check_if_All_Characters_Have_Equal_Number_of_Occurrences │ └── Solution.kt ├── 1944_Number_of_Visible_People_in_a_Queue │ └── Solution.kt ├── 1957_Delete_Characters_to_Make_Fancy_String │ └── Solution.kt ├── 1962_Remove_Stones_to_Minimize_the_Total │ └── Solution.kt ├── 1967_Number_of_Strings_That_Appear_as_Substrings_in_Word │ └── Solution.kt ├── 1971_Find_if_Path_Exists_in_Graph │ └── Solution.kt ├── 1974_Minimum_Time_to_Type_Word_Using_Special_Typewriter │ └── solution.js ├── 1979_Find_Greatest _Common_Divisor_of_Array │ └── Solution.kt ├── 1980_Find_Unique_Binary_String │ └── Solution.kt ├── 198_House_Robber │ └── solution.rb ├── 1991_Find_the_Middle_Index_in_Array │ └── Solution.java ├── 1992_Find_All_Groups_of_Farmland │ └── Solution.kt ├── 1996_The_Number_of_Weak_Characters_in_the_Game │ └── Solution.kt ├── 199_Binary_Tree_Right_Side_View │ └── Solution.scala ├── 19_Remove_Nth_Node_From_End_of_List │ └── Solution.kt ├── 1_Two_Sum │ └── Solution.java ├── 2000_Reverse_Prefix_of_Word │ └── Solution.kt ├── 2006_Count_Number_of_Pairs_With_Absolute_Difference_K │ └── solution.js ├── 2007_Find_Original_Array_From_Doubled_Array │ └── Solution.kt ├── 200_Number_of_Islands │ └── Solution.cpp ├── 2011_Final_Value_of_Variable_After_Performing_Operations │ └── solution.js ├── 201_Bitwise_AND_of_Numbers_Range │ └── solution.js ├── 2023_Number_of_Pairs_of_Strings_With_Concatenation_Equal_to_Target │ └── Solution.kt ├── 202_Happy_Number │ └── solution.rb ├── 2032_Two_Out_of_Three │ └── Solution.kt ├── 2034_Stock_Price_Fluctuation │ └── Solution.kt ├── 2037_Minimum_Number_of_Moves_to_Seat_Everyone │ └── Solution.kt ├── 203_Remove_Linked_List_Elements │ └── solution.rb ├── 2042_Check_if_Numbers_Are_Ascending_in_a_Sentence │ └── Solution.kt ├── 2043_Simple_Bank_System │ └── Solution.kt ├── 204_Count_Primes │ └── solution.rb ├── 2053_Kth_Distinct_String_in_an_Array │ └── Solution.kt ├── 2057_Smallest_Index_With_Equal_Value │ └── Solution.kt ├── 205_Isomorphic_Strings │ └── solution.rb ├── 2062_Count_Vowel_Substrings_of_a_String │ └── Solution.kt ├── 2063_Vowels_of_All_Substrings │ └── Solution.kt ├── 2068_Check_Whether_Two_Strings_are_Almost_Equivalent │ └── Solution.kt ├── 206_Reverse_Linked_List │ └── solution.rb ├── 2075_Decode_the_Slanted_Ciphertext │ └── Solution.kt ├── 2078_Two_Furthest_Houses_With_Different_Colors │ └── Solution.kt ├── 2079_Watering_Plants │ └── Solution.kt ├── 207_Course_Schedule │ └── solution.go ├── 2085_Count_Common_Words_With_One_Occurrence │ └── Solution.kt ├── 2089_Find_Target_Indices_After_Sorting_Array │ └── Solution.kt ├── 208_Implement_Trie_(Prefix_Tree) │ ├── Trie.java │ └── trie.go ├── 2095_Delete_the_Middle_Node_of_a_Linked_List │ └── Solution.kt ├── 209_Minimum_Size_Subarray_Sum │ └── solution.cpp ├── 20_Valid_Parentheses │ └── Solution.kt ├── 2102_Sequentially_Ordinal_Rank_Tracker │ └── SORTracker.kt ├── 2103_Rings_and_Rods │ └── Solution.kt ├── 2108_Find_First_Palindromic_String_in_the_Array │ └── Solution.kt ├── 2109_Adding_Spaces_to_a_String │ └── Solution.kt ├── 210_Course_Schedule_II │ ├── solution.py │ └── solution_dfs.py ├── 2114_Maximum_Number_of_Words_Found_in_Sentences │ └── Solution.kt ├── 2119_A_Number_After_a_Double_Reversal │ └── Solution.kt ├── 211_Add_and_Search_Word_-_Data_structure_design │ └── solution.go ├── 2120_Execution_of_All_Suffix_Instructions_Staying_in_a_Grid │ └── Solution.kt ├── 2124_Check_if_All_A's_Appears_Before_All_B's │ └── Solution.kt ├── 2125_Number_of_Laser_Beams_in_a_Bank │ └── Solution.kt ├── 2130_Maximum_Twin_Sum_of_a_Linked_List │ └── Solution.kt ├── 2131_Longest_Palindrome_by_Concatenating_Two_Letter_Words │ └── Solution.kt ├── 2138_Divide_a_String_Into_Groups_of_Size_k │ └── Solution.kt ├── 213_House_Robber_II │ └── solution.cpp ├── 2149_Rearrange_Array_Elements_by_Sign │ └── Solution.kt ├── 2150_Find_All_Lonely_Numbers_in_the_Array │ └── Solution.kt ├── 2154_Keep_Multiplying_Found_Values_by_Two │ └── Solution.kt ├── 215_Kth_Largest_Element_in_an_Array │ └── Solution.scala ├── 2160_Minimum_Sum_of_Four_Digit_Number_After_Splitting_Digits │ └── Solution.kt ├── 2161_Partition_Array_According_to_Given_Pivot │ └── Solution.kt ├── 2164_Sort_Even_and_Odd_Indices_Independently │ └── Solution.kt ├── 2165_Smallest_Value_of_the_Rearranged_Number │ └── Solution.kt ├── 2169_Count_Operations_to_Obtain_Zero │ └── Solution.kt ├── 216_Combination_Sum_III │ └── Solution.kt ├── 2176_Count_Equal_and_Divisible_Pairs_in_an_Array │ └── Solution.kt ├── 2177_Find_Three_Consecutive_Integers_That_Sum_to_a_Given_Number │ └── Solution.kt ├── 217_Contains_Duplicate │ └── solution.rb ├── 2180_Count_Integers_With_Even_Digit_Sum │ └── Solution.kt ├── 2181_Merge_Nodes_in_Between_Zeros │ └── Solution.kt ├── 2185_Counting_Words_With_a_Given_Prefix │ └── Solution.kt ├── 2186_Minimum_Number_of_Steps_to_Make_Two_Strings_Anagram_II │ └── Solution.kt ├── 2194_Cells_in_a_Range_on_an_Excel_Sheet │ └── Solution.kt ├── 2196_Create_Binary_Tree_From_Descriptions │ └── Solution.kt ├── 219_Contains_Duplicate_II │ └── Solution.kt ├── 21_Merge_Two_Sorted_Lists │ └── Solution.kt ├── 2200_Find_All_K-Distant_Indices_in_an_Array │ └── Solution.kt ├── 2206_Divide_Array_Into_Equal_Pairs │ └── Solution.kt ├── 2215_Find_the_Difference_of_Two_Arrays │ └── Solution.kt ├── 221_Maximal_Square │ └── Solution.kt ├── 2220_Minimum_Bit_Flips_to_Convert │ └── Solution.kt ├── 2221_Find_Triangular_Sum_of_an_Array │ └── Solution.kt ├── 2224_Minimum_Number_of_Operations_to_Convert_Time │ └── Solution.kt ├── 2225_Find_Players_With_Zero_or_One_Losses │ └── Solution.kt ├── 222_Count_Complete_Tree_Nodes │ └── Solution.kt ├── 2235_Add_Two_Integers │ └── Solution.kt ├── 2236_Root_Equals_Sum_of_Children │ └── Solution.kt ├── 223_Rectangle_Area │ └── Solution.kt ├── 2243_Calculate_Digit_Sum_of_a_String │ └── Solution.kt ├── 2248_Intersection_of_Multiple_Arrays │ └── Solution.kt ├── 224_Basic_Calculator │ └── Solution.kt ├── 2255_Count_Prefixes_of_a_Given_String │ └── Solution.kt ├── 2256_Minimum_Average_Difference │ └── Solution.kt ├── 2257_Count_Unguarded_Cells_in_the_Grid │ └── Solution.kt ├── 225_Implement_Stack_using_Queues │ └── Solution.kt ├── 2265_Count_Nodes_Equal_to_Average_of_Subtree │ └── Solution.kt ├── 226_Invert_Binary_Tree │ ├── solution.go │ └── solution.py ├── 2278_Percentage_of_Letter_in_String │ └── Solution.kt ├── 2279_Maximum_Bags_With_Full_Capacity_of_Rocks │ └── Solution.kt ├── 227_Basic_Calculator_II │ └── Solution.scala ├── 2283_Check_if_Number_Has_Equal_Digit_Count_and_Digit_Value │ └── Solution.kt ├── 228_Summary_Ranges │ └── Solution.kt ├── 2293_Min_Max_Game │ └── Solution.kt ├── 2295_Replace_Elements_in_an_Array │ └── Solution.kt ├── 229_Majority_Element_II │ └── Solution.kt ├── 22_Generate_Parentheses │ └── Solution.kt ├── 2309_Greatest_English_Letter_in_Upper_and_Lower_Case │ └── Solution.kt ├── 230_Kth_Smallest_Element_in_a_BST │ ├── solution.go │ └── solution.py ├── 2315_Count_Asterisks │ └── Solution.kt ├── 2319_Check_if_Matrix_Is_X-Matrix │ └── Solution.kt ├── 231_Power_of_Two │ └── solution.go ├── 2325_Decode_the_Message │ └── Solution.kt ├── 2326_Spiral_Matrix_IV │ └── Solution.kt ├── 232_Implement_Queue_using_Stacks │ └── Solution.kt ├── 2331_Evaluate_Boolean_Binary_Tree │ └── Solution.kt ├── 2336_Smallest_Number_in_Infinite_Set │ └── Solution.kt ├── 2341_Maximum_Number_of_Pairs_in_Array │ └── Solution.kt ├── 234_Palindrome_Linked_List │ └── Solution.java ├── 2351_First_Letter_to_Appear_Twice │ └── Solution.kt ├── 2352_Equal_Row_and_Column_Pairs │ └── Solution.kt ├── 2357_Make_Array_Zero_by_Subtracting_Equal_Amounts │ └── Solution.kt ├── 235_Lowest_Common_Ancestor_of_a_Binary_Search_Tree │ ├── solution.go │ └── solution.py ├── 2363_Merge_Similar_Items │ └── Solution.kt ├── 2367_Number_of_Arithmetic_Triplets │ └── Solution.kt ├── 236_Lowest_Common_Ancestor_of_a_Binary_Tree │ └── Solution.kt ├── 2373_Largest_Local_Values_in_a_Matrix │ └── Solution.kt ├── 237_Delete_Node_in_a_Linked_List │ └── solution.go ├── 2389_Longest_Subsequence_With_Limited_Sum │ └── Solution.kt ├── 238_Product_of_Array_Except_Self │ └── solution.py ├── 2390_Removing_Stars_From_a_String │ └── Solution.kt ├── 2391_Minimum_Amount_of_Time_to_Collect_Garbage │ └── Solution.kt ├── 2396_Strictly_Palindromic_Number │ └── Solution.kt ├── 2399_Check_Distances_Between_Same_Letters │ └── Solution.kt ├── 239_Sliding_Window_Maximum │ └── Solution.scala ├── 23_Merge_k_Sorted_Lists │ └── Solution.kt ├── 2405_Optimal_Partition_of_String │ └── Solution.kt ├── 240_Search_a_2D_Matrix_II │ ├── solution.go │ └── solutionbsearch.go ├── 2413_Smallest_Even_Multiple │ └── Solution.kt ├── 2415_Reverse_Odd_Levels_of_Binary_Tree │ └── Solution.kt ├── 2418_Sort_the_People │ └── Solution.kt ├── 2427_Number_of_Common_Factors │ └── Solution.kt ├── 2428_Maximum_Sum_of_an_Hourglass │ └── Solution.kt ├── 242_Valid_Anagram │ └── Solution.scala ├── 2433_Find_The_Original_Array_of_Prefix_Xor │ └── Solution.kt ├── 243_Shortest_Word_Distance │ └── Solution.java ├── 2441_Largest_Positive_Integer_That_Exists_With_Its_Negative │ └── Solution.kt ├── 2442_Count_Number_of_Distinct_Integers_After_Reverse_Operations │ └── Solution.kt ├── 2460_Apply_Operations_to_an_Array │ └── Solution.kt ├── 2469_Convert_the_Temperature │ └── Solution.kt ├── 246_Strobogrammatic_Number │ └── solution.go ├── 2475_Number_of_Unequal_Triplets_in_Array │ └── Solution.kt ├── 2482_Difference_Between_Ones_and_Zeros_in_Row_and_Column │ └── Solution.kt ├── 2483_Minimum_Penalty_for_a_Shop │ └── Solution.kt ├── 2485_Find_the_Pivot_Integer │ └── Solution.kt ├── 2486_Append_Characters_to_String_to_Make_Subsequence │ └── Solution.kt ├── 2487_Remove_Nodes_From_Linked_List │ └── Solution.kt ├── 2490_Circular_Sentence │ └── Solution.kt ├── 2491_Divide_Players_Into_Teams_of_Equal_Skill │ └── Solution.kt ├── 2496_Maximum_Value_of_a_String_in_an_Array │ └── Solution.kt ├── 24_Swap_Nodes_in_Pairs │ ├── Solution.java │ └── Solution.kt ├── 2500_Delete_Greatest_Value_in_Each_Row │ └── Solution.kt ├── 2502_Design_Memory_Allocator │ └── Allocator.kt ├── 2506_Count_Pairs_Of_Similar_Strings │ └── Solution.kt ├── 252_Meeting_Rooms │ └── Solution.kt ├── 253_Meeting_Rooms_II │ ├── Solution.java │ └── solution.go ├── 256_Paint_House │ └── Solution.java ├── 257_Binary_Tree_Paths │ └── Solution.kt ├── 258_Add_Digits │ └── Solution.kt ├── 25_Reverse_Nodes_in_k-Group │ └── Solution.kt ├── 263_Ugly_Number │ └── Solution.kt ├── 264_Ugly_Number_II │ └── Solution.kt ├── 266_Palindrome_Permutation │ └── Solution.kt ├── 268_Missing_Number │ └── solution.go ├── 269_Alien_Dictionary │ └── Solution.scala ├── 26_Remove_Duplicates_from_Sorted_Array │ └── Solution.kt ├── 270_Closest_Binary_Search_Tree_Value │ └── Solution.java ├── 273_Integer_to_English_Words │ └── Solution.scala ├── 274_H-Index │ └── solution.go ├── 275_H-Index_II │ └── solution.go ├── 277_Find_the_Celebrity │ └── solution.py ├── 278_First_bad_Version │ └── solution.py ├── 279_Perfect_Squares │ └── Solution.kt ├── 27_Remove_Element │ └── Solution.kt ├── 280_Wiggle_Sort │ └── Solution.kt ├── 283_Move_Zeroes │ └── solution.rb ├── 284_Peeking_Iterator │ └── solution.go ├── 285_Inorder_Successor_in_BST │ └── Solution.java ├── 287_Find_the_Duplicate_Number │ └── Solution.scala ├── 289_Game_of_Life │ └── Solution.kt ├── 28_Implement_strStr() │ └── Solution.kt ├── 290_Word_Pattern │ └── solution.js ├── 295_Find_Median_from_Data_Stream │ └── Solution.java ├── 297_Serialize_and_Deserialize_Binary_Tree │ └── Codec.java ├── 299_Bulls_and_Cows │ └── Solution.kt ├── 29_Divide_Two_Integers │ └── Solution.java ├── 2_Add_Two_Numbers │ └── Solution.java ├── 300_Longest_Increasing_Subsequence │ ├── Solution.java │ └── Solution.scala ├── 303_Range_Sum_Query_-_Immutable │ └── Solution.kt ├── 304_Range_Sum_Query_2D_-_Immutable │ └── Solution.java ├── 307_Range_Sum_Query_-_Mutable │ └── Solution.kt ├── 30_Substring_with_Concatenation_of_All_Words │ └── Solution.kt ├── 310_Minimum_Height_Trees │ └── Solution.kt ├── 316_Remove_Duplicate_Letters │ └── Solution.scala ├── 318_Maximum_Product_of_Word_Lengths │ └── Solution.kt ├── 31_Next_Permutation │ └── Solution.kt ├── 322_Coin_Change │ └── Solution.scala ├── 323_Number_of_Connected_Components_in_an_Undirected_Graph │ ├── Solution.scala │ └── solution.go ├── 326_Power_of_Three │ ├── Solution.java │ └── solution.rb ├── 328_Odd_Even_Linked_List │ └── solution.go ├── 329_Longest_Increasing_Path_in_a_Matrix │ └── Solution.java ├── 32_Longest_Valid_Parentheses │ └── Solution.java ├── 331_Verify_Preorder_Serialization_of_a_Binary_Tree │ └── Solution.kt ├── 332_Reconstruct_Itinerary │ └── Solution.scala ├── 334_Increasing_Triplet_Subsequence │ └── solution.js ├── 338_Counting_Bits │ ├── solution.go │ └── solution.rb ├── 339_Nested_List_Weight_Sum │ └── Solution.kt ├── 33_Search_in_Rotated_Sorted_Array │ └── Solution.kt ├── 340_Longest_Substring_with_At_Most_K_Distinct_Characters │ └── Solution.java ├── 341_Flatten_Nested_List_Iterator │ └── Solution.kt ├── 342_Power_of_Four │ └── Solution.kt ├── 343_Integer_Break │ └── Solution.kt ├── 344_Reverse_String │ ├── Solution.cpp │ └── solution.go ├── 345_Reverse_Vowels_of_a_String │ └── Solution.kt ├── 346_Moving_Average_from_Data_Stream │ └── Solution.kt ├── 347_Top_K_Frequent_Elements │ └── Solution.scala ├── 348_Design_Tic-Tac-Toe │ └── TicTacToe.java ├── 349_Intersection_of_Two_Arrays │ └── solution.rb ├── 34_Find_First_and_Last_Position_of_Element_in_Sorted_Array │ └── Solution.kt ├── 350_Intersection_of_Two_Arrays_II │ └── Solution.kt ├── 352_Data_Stream_as_Disjoint_Intervals │ └── Solution.kt ├── 354_Russian_Doll_Envelopes │ └── Solution.java ├── 355_Design_Twitter │ └── Solution.kt ├── 359_Logger_Rate_Limiter │ └── Solution.kt ├── 35_Search_Insert_Position │ ├── Solution.py │ └── solution.go ├── 362_Design_Hit_Counter │ └── HitCounter.scala ├── 363_Max_Sum_of_Rectangle_No_Larger_Than_K │ └── Solution.kt ├── 364_Nested_List_Weight_Sum_II │ └── Solution.java ├── 365_Water_and_Jug_Problem │ └── solution.cpp ├── 366_Find_Leaves_of_Binary_Tree │ └── Solution.kt ├── 367_Valid_Perfect_Square │ └── solution.c ├── 368_Largest_Divisible_Subset │ └── solution.go ├── 36_Valid_Sudoku │ └── Solution.py ├── 371_Sum_of_Two_Integers │ └── Solution.kt ├── 374_Guess_Number_Higher_or_Lower │ └── Solution.kt ├── 376_Wiggle_Subsequence │ └── Solution.java ├── 377_Combination_Sum_IV │ └── Solution.java ├── 378_Kth_Smallest_Element_in_a_Sorted_Matrix │ └── Solution.scala ├── 37_Sudoku_Solver │ └── Solution.py ├── 380_Insert_Delete_GetRandom_O(1) │ └── solution.go ├── 381_Insert_Delete_GetRandom_O(1)_-_Duplicates_allowed │ └── Solution.kt ├── 382_Linked_List_Random_Node │ └── Solution.kt ├── 383_Ransom_Note │ └── solution.py ├── 384_Shuffle_an_Array │ └── solution.ts ├── 385_Mini_Parser │ └── Solution.kt ├── 386_Lexicographical_Numbers │ └── Solution.kt ├── 387_First_Unique_Character_in_a_String │ └── Solution.cpp ├── 388_Longest_Absolute_File_Path │ └── Solution.kt ├── 389_Find_the_Difference │ └── solution.go ├── 38_Count_and_Say │ └── Solution.py ├── 390_Elimination_Game │ └── Solution.kt ├── 392_Is_Subsequence │ └── solution.go ├── 393_UTF-8_Validation │ └── Solution.kt ├── 394_Decode_String │ └── Solution.scala ├── 397_Integer_Replacement │ └── Solution.kt ├── 399_Evaluate_Division │ └── Solution.scala ├── 39_Combination_Sum │ └── Solution.py ├── 3_Longest_Substring_Without_Repeating_Characters │ └── Solution.java ├── 402_Remove_K_Digits │ └── solution.go ├── 404_Sum_of_Left_Leaves │ └── Solution.kt ├── 406_Queue_Reconstruction_by_Height │ └── solution.go ├── 409_Longest_Palindrome │ └── Solution.kt ├── 40_Combination_Sum_II │ └── Solution.kt ├── 412_Fizz_Buzz │ └── Solution.scala ├── 413_Arithmetic_Slices │ └── solution.go ├── 414_Third_Maximum_Number │ └── Solution.kt ├── 415_Add_Strings │ └── Solution.scala ├── 417_Pacific_Atlantic_Water_Flow │ └── Solution.java ├── 419_Battleships_in_a_Board │ └── solution.rb ├── 41_First_Missing_positive │ └── Solution.py ├── 423_Reconstruct_Original_Digits_from_English │ └── Solution.java ├── 424_Longest_Repeating_Character_Replacement │ └── Solution.kt ├── 427_Construct_Quad_Tree │ └── Solution.kt ├── 428_Serialize_and_Deserialize_N-ary_Tree │ └── Codec.kt ├── 429_N-ary_Tree_Level_Order_Traversal │ ├── Solution.kt │ └── solution.py ├── 42_Trapping_Rain_Water │ └── Solution.py ├── 430_Flatten_a_Multilevel_Doubly_Linked_List │ └── Solution.kt ├── 432_All_O`one_Data_Structure │ └── Solution.kt ├── 433_Minimum_Genetic_Mutation │ └── Solution.kt ├── 434_Number_of_Segments_in_a_String │ └── Solution.kt ├── 435_Non-overlapping_Intervals │ └── Solution.kt ├── 437_Path_Sum_III │ └── Solution.kt ├── 438_Find_All_Anagrams_in_a_String │ └── solution.go ├── 43_Multiply_Strings │ └── Solution.py ├── 441_Arranging_Coins │ └── Solution.kt ├── 442_Find_All_Duplicates_in_an_Array │ ├── Solution.scala │ └── Solution2.scala ├── 443_String_Compression │ └── solution.go ├── 445_Add_Two_Numbers_II │ └── Solution.scala ├── 448_Find_All_Numbers_Disappeared_in_an_Array │ └── Solution.kt ├── 449_Serialize_and_Deserialize_BST │ └── Codec.scala ├── 44_Wildcard_Matching │ └── solution.py ├── 450_Delete_Node_in_a_BST │ └── Solution.kt ├── 451_Sort_Characters_By_Frequency │ └── solution.go ├── 452_Minimum_Number_of_Arrows_to_Burst_Balloons │ └── Solution.kt ├── 454_4Sum_II │ └── Solution.kt ├── 456_132_Pattern │ └── Solution.kt ├── 458_Poor_Pigs │ └── Solution.kt ├── 459_Repeated_Substring_Pattern │ └── Solution.kt ├── 45_Jump_Game_II │ └── solution.rb ├── 460_LFU_Cache │ └── LFUCache.java ├── 461_Hamming_Distance │ └── Solution.cpp ├── 462_Minimum_Moves_to_Equal_Array_Elements_II │ └── Solution.java ├── 463_Island_Perimeter │ └── Solution.cpp ├── 468_Validate_IP_Address │ └── solution.go ├── 46_Permutations │ └── solution.rb ├── 473_Matchsticks_to_Square │ └── Solution.kt ├── 474_Ones_and_Zeroes │ └── Solution.java ├── 476_Number_Complement │ └── Solution.cpp ├── 478_Generate_Random_Point_in_a_Circle │ └── Solution.java ├── 47_Permutations_II │ └── solution.rb ├── 482_License_Key_Formatting │ └── Solution.kt ├── 485_Max_Consecutive_Ones │ └── Solution.kt ├── 489_Robot_Room_Cleaner │ └── Solution.kt ├── 48_Rotate_Image │ └── solution.rb ├── 491_Increasing_Subsequences │ └── Solution.kt ├── 496_Next_Greater_Element_I │ └── Solution.cpp ├── 498_Diagonal_Traverse │ └── Solution.scala ├── 49_Group_Anagrams │ └── solution.rb ├── 4_Median_of_Two_Sorted_Arrays │ └── Solution.java ├── 500_Keyboard_Row │ └── Solution.kt ├── 503_Next_Greater_Element_II │ └── Solution.kt ├── 505_The_Maze_II │ └── Solution.java ├── 506_Relative_Ranks │ └── Solution.kt ├── 508_Most_Frequent_Subtree_Sum │ └── Solution.kt ├── 509_Fibonacci_Number │ └── solution.c ├── 513_Find_Bottom_Left_Tree_Value │ └── solution.py ├── 515_Find_Largest_Value_in_Each_Tree_Row │ └── solution.js ├── 518_Coin_Change_2 │ └── solution.go ├── 51_N-Queens │ └── solution.rb ├── 520_Detect_Capital │ └── Solution.kt ├── 523_Continuous_Subarray_Sum │ └── Solution.kt ├── 524_Longest_Word_in_Dictionary_through_Deleting │ └── Solution.kt ├── 525_Contiguous_Array │ ├── solution.go │ └── solution.py ├── 526_Beautiful_Arrangement │ └── Solution.kt ├── 528_Random_Pick_with_Weight │ └── solution.go ├── 529_Minesweeper │ └── Solution.kt ├── 52_N-Queens_II │ └── solution.rb ├── 530_Minimum_Absolute_Difference_in_BST │ └── Solution.kt ├── 532_K-diff_Pairs_in_an_Array │ └── Solution.scala ├── 535_Encode_and_Decode_TinyURL │ └── Solution.cpp ├── 536_Construct_Binary_Tree_from_String │ └── Solution.java ├── 537_Complex_Number_Multiplication │ └── Solution.kt ├── 538_Convert_BST_to_Greater_Tree │ └── solution.go ├── 539_Minimum_Time_Difference │ └── Solution.kt ├── 53_Maximum_Subarray │ └── solution.py ├── 540_Single_Element_in_a_Sorted_Array │ └── solution.go ├── 541_Reverse_String_II │ └── Solution.kt ├── 542_01_Matrix │ └── Solution.kt ├── 543_Diameter_of_Binary_Tree │ └── solution.py ├── 544_Output_Contest_Matches │ └── Solution.kt ├── 547_Friend_Circles │ └── Solution.scala ├── 54_Spiral_Matrix │ └── solution.rb ├── 551_Student_Attendance_Record_I │ └── Solution.kt ├── 554_Brick_Wall │ └── Solution.java ├── 556_Next_Greater_Element_III │ └── Solution.kt ├── 557_Reverse_Words_in_a_String_III │ └── Solution.cpp ├── 559_Maximum_Depth_of_N-ary_Tree │ └── solution.js ├── 55_Jump_Game │ └── solution.rb ├── 560_Subarray_Sum_Equals_K │ └── solution.py ├── 561_Array_Partition_I │ └── Solution.kt ├── 565_Array_Nesting │ └── Solution.kt ├── 566_Reshape_the_Matrix │ └── Solution.kt ├── 567_Permutation_in_String │ └── solution.go ├── 56_Merge_Intervals │ └── solution.rb ├── 572_Subtree_of_Another_Tree │ └── Solution.java ├── 573_Squirrel_Simulation │ └── Solution.kt ├── 575_Distribute_Candies │ └── Solution.scala ├── 576_Out_of_Boundary_Paths │ └── Solution.kt ├── 57_Insert_Interval │ └── solution.rb ├── 581_Shortest_Unsorted_Continuous_Subarray │ └── solution.go ├── 582_Kill_Process │ └── Solution.scala ├── 583_Delete_Operation_for_Two_Strings │ └── Solution.java ├── 587_Erect_the_Fence │ └── Solution.kt ├── 588_Design_In-Memory_File_System │ └── FileSystem.java ├── 589_N-ary_Tree_Preorder_Traversal │ └── Solution.cpp ├── 58_Length_of_Last_Word │ └── solution.py ├── 590_N-ary_Tree_Postorder_Traversal │ └── Solution.cpp ├── 592_Fraction_Addition_and_Subtraction │ └── Solution.java ├── 594_Longest_Harmonious_Subsequence │ └── Solution.kt ├── 599_Minimum_Index_Sum_of_Two_Lists │ └── Solution.kt ├── 59_Spiral_Matrix_II │ └── solution.rb ├── 5_Longest_Palindromic_Substring │ ├── solution.go │ └── solution_using_manacher.go ├── 606_Construct_String_from_Binary_Tree │ └── Solution.java ├── 609_Find_Duplicate_File_in_System │ └── Solution.scala ├── 60_Permutation_Sequence │ └── solution.rb ├── 611_Valid_Triangle_Number │ └── Solution.kt ├── 617_Merge_Two_Binary_Trees │ └── Solution.kt ├── 61_Rotate_List │ └── solution.rb ├── 621_Task_Scheduler │ └── Solution.kt ├── 622_Design_Circular_Queue │ ├── MyCircularQueue.java │ ├── MyCircularQueue.kt │ ├── MyCircularQueue.scala │ ├── my_circular_queue.cpp │ └── my_circular_queue.py ├── 623_Add_One_Row_to_Tree │ └── Solution.kt ├── 624_Maximum_Distance_in_Arrays │ └── Solution.scala ├── 629_K_Inverse_Pairs_Array │ └── Solution.kt ├── 62_Unique_Paths │ └── solution.rb ├── 630_Course_Schedule_III │ └── Solution.java ├── 633_Sum_of_Square_Numbers │ └── Solution.kt ├── 636_Exclusive_Time_of_Functions │ └── Solution.scala ├── 637_Average_of_Levels_in_Binary_Tree │ └── Solution.scala ├── 63_Unique_Paths_II │ └── solution.rb ├── 640_Solve_the_Equation │ └── Solution.kt ├── 641_Design_Circular_Deque │ └── Solution.kt ├── 642_Design_Search_Autocomplete_System │ └── AutocompleteSystem.kt ├── 645_Set_Mismatch │ └── solution.go ├── 646_Maximum_Length_of_Pair_Chain │ └── Solution.kt ├── 647_Palindromic_Substrings │ └── Solution.java ├── 648_Replace_Words │ └── solution.js ├── 64_Minimum_Path_Sum │ └── solution.rb ├── 654_Maximum_Binary_Tree │ └── solution.go ├── 655_Print_Binary_Tree │ └── Solution.kt ├── 657_Robot_Return_to_Origin │ └── Solution.cpp ├── 658_Find_K_Closest_Elements │ └── Solution.kt ├── 659_Split_Array_into_Consecutive_Subsequences │ └── Solution.kt ├── 65_Valid_Number │ └── Solution.kt ├── 662_Maximum_Width_of_Binary_Tree │ └── Solution.kt ├── 665_Non-decreasing_Array │ └── Solution.java ├── 667_Beautiful_Arrangement_II │ └── Solution.java ├── 669_Trim_a_Binary_Search_Tree │ └── Solution.kt ├── 66_Plus_One │ └── solution.py ├── 670_Maximum_Swap │ └── Solution.kt ├── 671_Second_Minimum_Node_In_a_Binary_Tree │ └── Solution.kt ├── 673_Number_of_Longest_Increasing_Subsequence │ └── solution.js ├── 676_Implement_Magic_Dictionary │ └── Solution.kt ├── 677_Map_Sum_Pairs │ └── Solution.kt ├── 678_Valid_Parenthesis_String │ └── solution.py ├── 67_Add_Binary │ └── solution.py ├── 680_Valid_Palindrome_II │ └── Solution.kt ├── 682_Baseball_Game │ └── Solution.kt ├── 684_Redundant_Connection │ └── Solution.kt ├── 686_Repeated_String_Match │ └── Solution.kt ├── 68_Text_Justification │ └── Solution.scala ├── 692_Top_K_Frequent_Words │ └── Solution.java ├── 694_Number_of_Distinct_Islands │ └── Solution.java ├── 695_Max_Area_of_Island │ └── Solution.scala ├── 696_Count_Binary_Substrings │ └── Solution.java ├── 697_Degree_of_an_Array │ └── Solution.kt ├── 69_Sqrt(x) │ └── solution.py ├── 6_ZigZag_Conversion │ └── Solution.java ├── 700_Search_in_a_Binary_Search_Tree │ ├── Solution.cpp │ └── solution.go ├── 701_Insert_into_a_Binary_Search_Tree │ └── solution.rb ├── 702_Search_in_a_Sorted_Array_of_Unknown_Size │ └── Solution.scala ├── 703_Kth_Largest_Element_in_a_Stream │ └── KthLargest.kt ├── 704_Binary_Search │ └── Solution.scala ├── 705_Design_HashSet │ └── Solution.kt ├── 706_Design_HashMap │ └── MyHashMap.scala ├── 707_Design_Linked_List │ └── Solution.kt ├── 709_To_Lower_Case │ └── solution.cpp ├── 70_Climbing_Stairs │ ├── Solution.java │ ├── solution.py │ └── solution.rb ├── 713_Subarray_Product_Less_Than_K │ └── Solution.kt ├── 714_Best_Time_to_Buy_and_Sell_Stock_with_Transaction_Fee │ └── Solution.java ├── 718_Maximum_Length_of_Repeated_Subarray │ └── Solution.kt ├── 71_Simplify_Path │ └── solution.rb ├── 720_Longest_Word_in_Dictionary │ └── Solution.kt ├── 721_Accounts_Merge │ └── Solution.scala ├── 722_Remove_Comments │ └── Solution.kt ├── 723_Candy_Crush │ └── solution.cpp ├── 724_Find_Pivot_Index │ └── Solution.java ├── 725_Split_Linked_List_in_Parts │ └── Solution.kt ├── 728_Self_Dividing_Numbers │ └── Solution.cpp ├── 729_My_Calendar_I │ └── Solution.java ├── 72_Edit_Distance │ └── solution.rb ├── 732_My_Calendar_III │ └── Solution.kt ├── 733_Flood_Fill │ └── solution.py ├── 735_Asteroid_Collision │ └── Solution.java ├── 739_Daily_Temperatures │ └── solution.rb ├── 73_Set_Matrix_Zeroes │ └── Solution.cpp ├── 740_Delete_and_Earn │ └── Solution.kt ├── 743_Network_Delay_Time │ └── Solution.kt ├── 744_Find_Smallest_Letter_Greater_Than_Target │ └── Solution.kt ├── 745_Prefix_and_Suffix_Search │ └── Solution.java ├── 746_Min_Cost_Climbing_Stairs │ └── Solution.kt ├── 748_Shortest_Completing_Word │ └── Solution.kt ├── 74_Search_a_2D_Matrix │ └── solution.rb ├── 750_Number_Of_Corner_Rectangles │ └── solution.go ├── 752_Open_the_Lock │ └── Solution.scala ├── 759_Employee_Free_Time │ └── Solution.scala ├── 75_Sort_Colors │ ├── Solution.cpp │ └── solution.go ├── 760_Find_Anagram_Mappings │ └── Solution.scala ├── 762_Prime_Number_of_Set_Bits_in_Binary_Representation │ └── Solution.kt ├── 763_Partition_Labels │ └── solution.go ├── 766_Toeplitz_Matrix │ └── Solution.kt ├── 767_Reorganize_String │ └── Solution.kt ├── 76_Minimum_Window_Substring │ └── solution.rb ├── 771_Jewels_and_Stones │ └── solution.py ├── 773_Sliding_Puzzle │ └── Solution.kt ├── 775_Global_and_Local_Inversions │ └── Solution.java ├── 776_Split_BST │ └── Solution.java ├── 77_Combinations │ └── solution.rb ├── 781_Rabbits_in_Forest │ └── Solution.kt ├── 783_Minimum_Distance_Between_BST_Nodes │ └── Solution.kt ├── 784_Letter_Case_Permutation │ └── Solution.scala ├── 785_Is_Graph_Bipartite? │ └── Solution.scala ├── 787_Cheapest_Flights_Within_K_Stops │ └── Solution.java ├── 788_Rotated_Digits │ └── Solution.kt ├── 789_Escape_The_Ghosts │ └── Solution.kt ├── 78_Subsets │ ├── Solution.java │ └── solution.rb ├── 791_Custom_Sort_String │ └── Solution.kt ├── 792_Number_of_Matching_Subsequences │ └── Solution.kt ├── 796_Rotate_String │ └── Solution.kt ├── 797_All_Paths_From_Source_to_Target │ └── Solution.scala ├── 79_Word_Search │ └── Solution.cpp ├── 7_Reverse_Integer │ └── Solution.kt ├── 802_Find_Eventual_Safe_States │ └── Solution.kt ├── 804_Unique_Morse_Code_Words │ └── Solution.cpp ├── 806_Number_of_Lines_To_Write_String │ └── Solution.kt ├── 807_Max_Increase_to_Keep_City_Skyline │ └── Solution.cpp ├── 809_Expressive_Words │ └── Solution.kt ├── 80_Remove_Duplicates_from_Sorted_Array_II │ └── solution.rb ├── 811_Subdomain_Visit_Count │ └── Solution.scala ├── 814_Binary_Tree_Pruning │ ├── Solution.kt │ └── solution.py ├── 816_Ambiguous_Coordinates │ └── Solution.java ├── 817_Linked_List_Components │ └── Solution.kt ├── 819_Most_Common_Word │ └── solution.go ├── 81_Search_in_Rotated_Sorted_Array_II │ └── Solution.kt ├── 820_Short_Encoding_of_Words │ ├── solution.py │ └── solution_trie.py ├── 821_Shortest_Distance_to_a_Character │ └── solution.go ├── 823_Binary_Trees_With_Factors │ └── Solution.kt ├── 824_Goat_Latin │ └── solution.rb ├── 827_Making_A_Large_Island │ └── Solution.kt ├── 829_Consecutive_Numbers_Sum │ └── Solution.scala ├── 82_Remove_Duplicates_from_Sorted_List_II │ └── solution.rb ├── 830_Positions_of_Large_Groups │ └── Solution.kt ├── 831_Masking_Personal_Information │ └── Solution.kt ├── 832_Flipping_an_Image │ └── Solution.cpp ├── 833_Find_And_Replace_in_String │ └── Solution.kt ├── 835_Image_Overlap │ └── Solution.kt ├── 838_Push_Dominoes │ └── Solution.kt ├── 83_Remove_Duplicates_from_Sorted_List │ └── solution.py ├── 841_Keys_and_Rooms │ └── Solution.cpp ├── 844_Backspace_String_Compare │ └── solution.py ├── 847_Shortest_Path_Visiting_All_Nodes │ └── Solution.kt ├── 848_Shifting_Letters │ └── Solution.kt ├── 84_Largest_Rectangle_in_Histogram │ └── solution.rb ├── 852_Peak_Index_in_a_Mountain_Array │ └── Solution.cpp ├── 856_Score_of_Parentheses │ └── Solution.kt ├── 858_Mirror_Reflection │ └── Solution.kt ├── 85_Maximal_Rectangle │ └── Solution.kt ├── 860_Lemonade_Change │ └── Solution.kt ├── 861_Score_After_Flipping_Matrix │ └── Solution.scala ├── 863_All_Nodes_Distance_K_in_Binary_Tree │ └── solution.go ├── 865_Smallest_Subtree_with_all_the_Deepest_Nodes │ └── Solution.kt ├── 867_Transpose_Matrix │ └── Solution.kt ├── 869_Reordered_Power_of_2 │ └── Solution.java ├── 86_Partition_List │ └── solution.py ├── 872_Leaf-Similar_Trees │ └── Solution.kt ├── 874_Walking_Robot_Simulation │ └── Solution.kt ├── 875_Koko_Eating_Bananas │ └── Solution.kt ├── 876_Middle_of_the_Linked_List │ └── solution.c ├── 881_Boats_to_Save_People │ └── solution.ts ├── 884_Uncommon_Words_from_Two_Sentences │ └── Solution.kt ├── 885_Spiral_Matrix_III │ └── Solution.kt ├── 886_Possible_Bipartition │ └── solution.go ├── 889_Construct_Binary_Tree_from_Preorder_and_Postorder_Traversal │ └── Solution.kt ├── 88_Merge_Sorted_Array │ └── solution.py ├── 890_Find_and_Replace_Pattern │ └── Solution.cpp ├── 893_Groups_of_Special-Equivalent_Strings │ └── Solution.kt ├── 895_Maximum_Frequency_Stack │ └── FreqStack.java ├── 896_Monotonic_Array │ └── Solution.kt ├── 897_Increasing_Order_Search_Tree │ ├── Solution.java │ └── Solution.kt ├── 899_Orderly_Queue │ └── Solution.kt ├── 89_Gray_Code │ └── Solution.cpp ├── 8_String_to_Integer_(atoi) │ └── Solution.kt ├── 900_RLE_Iterator │ └── RLEIterator.kt ├── 901_Online_Stock_Span │ └── solution.go ├── 905_Sort_Array_By_Parity │ └── Solution.cpp ├── 906_Super_Palindromes │ └── Solution.java ├── 90_Subsets_II │ └── Solution.kt ├── 910_Smallest_Range_II │ └── Solution.kt ├── 916_Word_Subsets │ └── Solution.java ├── 917_Reverse_Only_Letters │ └── Solution.kt ├── 918_Maximum_Sum_Circular_Subarray │ └── solution.go ├── 919_Complete_Binary_Tree_Inserter │ └── CBTInserter.kt ├── 91_Decode_Ways │ └── Solution.cpp ├── 921_Minimum_Add_to_Make_Parentheses_Valid │ └── Solution.kt ├── 922_Sort_Array_By_Parity_II │ └── Solution.cpp ├── 923_3Sum_With_Multiplicity │ └── Solution.java ├── 929_Unique_Email_Addresses │ └── solution.py ├── 92_Reverse_Linked_List_II │ └── Solution.cpp ├── 930_Binary_Subarrays_With_Sum │ └── Solution.kt ├── 931_Minimum_Falling_Path_Sum │ └── Solution.kt ├── 933_Number_of_Recent_Calls │ └── RecentCounter.scala ├── 937_Reorder_Data_in_Log_Files │ └── solution.go ├── 938_Range_Sum_of_BST │ └── Solution.cpp ├── 93_Restore_IP_Addresses │ └── Solution.cpp ├── 942_DI_String_Match │ └── Solution.cpp ├── 944_Delete_Columns_to_Make_Sorted │ └── Solution.kt ├── 946_Validate_Stack_Sequences │ ├── Solution.java │ ├── Solution.kt │ ├── Solution.scala │ ├── solution.c │ ├── solution.cpp │ ├── solution.go │ ├── solution.py │ └── solution.rb ├── 947_Most_Stones_Removed_with_Same_Row_or_Column │ └── Solution.kt ├── 948_Bag_of_Tokens │ └── Solution.kt ├── 94_Binary_Tree_Inorder_Traversal │ └── Solution.cpp ├── 950_Reveal_Cards_In_Increasing_Order │ └── Solution.kt ├── 951_Flip_Equivalent_Binary_Trees │ └── Solution.kt ├── 953_Verifying_an_Alien_Dictionary │ └── Solution.scala ├── 958_Check_Completeness_of_a_Binary_Tree │ └── Solution.kt ├── 959_Regions_Cut_By_Slashes │ └── Solution.kt ├── 95_Unique_Binary_Search_Trees_II │ └── solution.go ├── 961_N-Repeated_Element_in_Size_2N_Array │ └── Solution.cpp ├── 965_Univalued_Binary_Tree │ └── solution.c ├── 966_Vowel_Spellchecker │ └── Solution.java ├── 967_Numbers_With_Same_Consecutive_Differences │ └── Solution.kt ├── 969_Pancake_Sorting │ └── Solution.java ├── 96_Unique_Binary_Search_Trees │ └── solution.go ├── 970_Powerful_Integers │ └── Solution.java ├── 971_Flip_Binary_Tree_To_Match_Preorder_Traversal │ └── Solution.java ├── 973_K_Closest_Points_to_Origin │ └── solution.go ├── 976_Largest_Perimeter_Triangle │ └── Solution.kt ├── 977_Squares_of_a_Sorted_Array │ └── Solution.cpp ├── 979_Distribute_Coins_in_Binary_Tree │ └── solution.js ├── 97_Interleaving_String │ └── Solution.kt ├── 980_Unique_Paths_III │ └── solution.cpp ├── 981_Time_Based_Key-Value_Store │ └── TimeMap.scala ├── 983_Minimum_Cost_For_Tickets │ ├── Solution.kt │ └── solution.py ├── 985_Sum_of_Even_Numbers_After_Queries │ └── Solution.kt ├── 986_Interval_List_Intersections │ └── solution.go ├── 987_Vertical_Order_Traversal_of_a_Binary_Tree │ └── Solution.kt ├── 989_Add_to_Array-Form_of_Integer │ └── Solution.kt ├── 98_Validate_Binary_Search_Tree │ └── solution.py ├── 990_Satisfiability_of_Equality_Equations │ └── Solution.kt ├── 991_Broken_Calculator │ └── solution.go ├── 993_Cousins_in_Binary_Tree │ └── solution.c ├── 994_Rotting_Oranges │ └── solution.go ├── 997_Find_the_Town_Judge │ └── Solution.cpp ├── 999_Available_Captures_for_Rook │ └── solution.js ├── 99_Recover_Binary_Search_Tree │ └── Solution.cpp └── 9_Palindrome_Number │ └── Solution.kt ├── Challenge ├── 30-Day_LeetCoding_Challenge │ ├── Week_1:_April_1st–April_7th │ │ ├── 122_Best_Time_to_Buy_and_Sell_Stock_II │ │ │ └── solution.py │ │ ├── 136_Single_Number │ │ │ ├── Solution.java │ │ │ ├── solution.py │ │ │ └── solution.rb │ │ ├── 202_Happy_Number │ │ │ └── solution.rb │ │ ├── 283_Move_Zeroes │ │ │ └── solution.rb │ │ ├── 49_Group_Anagrams │ │ │ └── solution.rb │ │ ├── 53_Maximum_Subarray │ │ │ └── solution.py │ │ └── Counting_Elements │ │ │ └── Solution.cpp │ ├── Week_2:_April_8th–April_14th │ │ ├── 1046_Last_Stone_Weight │ │ │ └── solution.py │ │ ├── 155_Min_Stsck │ │ │ └── solution.py │ │ ├── 525_Contiguous_Array │ │ │ └── solution.py │ │ ├── 543_Diameter_of_Binary_Tree │ │ │ └── solution.py │ │ ├── 844_Backspace_String_Compare │ │ │ └── solution.py │ │ └── Perform_String_Shifts │ │ │ └── solution.py │ ├── Week_3:_April_15th-April_21st │ │ ├── 1008_Construct_Binary_Search_Tree_from_Preorder_Traversal │ │ │ └── solution.rb │ │ ├── 200_Number_of_Islands │ │ │ └── Solution.cpp │ │ ├── 238_Product_of_Array_Except_Self │ │ │ └── solution.py │ │ ├── 33_Search_in_Rotated_Sorted_Array │ │ │ └── Solution.kt │ │ ├── 678_Valid_Parenthesis_String │ │ │ └── solution.py │ │ └── Leftmost_Column_with_at_Least_a_One │ │ │ └── solution.py │ └── Week_4:_April_22nd–April_28th │ │ ├── 146_LRU_Cache │ │ └── LRUCache.java │ │ ├── 55_Jump_Game │ │ └── solution.rb │ │ └── 560_Subarray_Sum_Equals_K │ │ └── solution.py ├── June_LeetCoding_Challenge │ ├── Week_1:_June_1st–June_7th │ │ ├── 1029_Two_City_Scheduling │ │ │ └── solution.go │ │ ├── 226_Invert_Binary_Tree │ │ │ ├── solution.go │ │ │ └── solution.py │ │ ├── 237_Delete_Node_in_a_Linked_List │ │ │ └── solution.go │ │ ├── 344_Reverse_String │ │ │ ├── Solution.cpp │ │ │ └── solution.go │ │ ├── 406_Queue_Reconstruction_by_Height │ │ │ └── solution.go │ │ ├── 518_Coin_Change_2 │ │ │ └── solution.go │ │ └── 528_Random_Pick_with_Weight │ │ │ └── solution.go │ ├── Week_2:_June_8th–June_14th │ │ ├── 231_Power_of_Two │ │ │ └── solution.go │ │ ├── 35_Search_Insert_Position │ │ │ ├── Solution.py │ │ │ └── solution.go │ │ ├── 368_Largest_Divisible_Subset │ │ │ └── solution.go │ │ ├── 380_Insert_Delete_GetRandom_O(1) │ │ │ └── solution.go │ │ ├── 392_Is_Subsequence │ │ │ └── solution.go │ │ ├── 75_Sort_Colors │ │ │ ├── Solution.cpp │ │ │ └── solution.go │ │ └── 787_Cheapest_Flights_Within_K_Stops │ │ │ └── Solution.java │ └── Week_3:_June_15th–June_21st │ │ ├── 130_Surrounded_Regions │ │ └── solution.go │ │ ├── 275_H-Index_II │ │ └── solution.go │ │ ├── 468_Validate_IP_Address │ │ └── solution.go │ │ └── 700_Search_in_a_Binary_Search_Tree │ │ ├── Solution.cpp │ │ └── solution.go └── May_LeetCoding_Challenge │ ├── Week_1:_May_1st–May_7th │ ├── 169_Majority_Element │ │ └── Solution.kt │ ├── 278_First_bad_Version │ │ └── solution.py │ ├── 383_Ransom_Note │ │ └── solution.py │ ├── 387_First_Unique_Character_in_a_String │ │ └── Solution.cpp │ ├── 476_Number_Complement │ │ └── Solution.cpp │ ├── 771_Jewels_and_Stones │ │ └── solution.py │ └── 993_Cousins_in_Binary_Tree │ │ └── solution.c │ ├── Week_2:_May_8th–May_14th │ ├── 1232_Check_If_It_Is_a_Straight_Line │ │ └── solution.py │ ├── 208_Implement_Trie_(Prefix_Tree) │ │ ├── Trie.java │ │ └── trie.go │ ├── 367_Valid_Perfect_Square │ │ └── solution.c │ ├── 402_Remove_K_Digits │ │ └── solution.go │ ├── 540_Single_Element_in_a_Sorted_Array │ │ └── solution.go │ ├── 733_Flood_Fill │ │ └── solution.py │ └── 997_Find_the_Town_Judge │ │ └── Solution.cpp │ ├── Week_3:_May_15th–May_21st │ ├── 1277_Count_Square_Submatrices_with_All_Ones │ │ └── solution.go │ ├── 230_Kth_Smallest_Element_in_a_BST │ │ ├── solution.go │ │ └── solution.py │ ├── 328_Odd_Even_Linked_List │ │ └── solution.go │ ├── 438_Find_All_Anagrams_in_a_String │ │ └── solution.go │ ├── 567_Permutation_in_String │ │ └── solution.go │ ├── 901_Online_Stock_Span │ │ └── solution.go │ └── 918_Maximum_Sum_Circular_Subarray │ │ └── solution.go │ ├── Week_4:_May_22nd–May_28th │ ├── 1008_Construct_Binary_Search_Tree_from_Preorder_Traversal │ │ ├── solution.go │ │ └── solution.rb │ ├── 1035_Uncrossed_Lines │ │ └── solution.go │ ├── 338_Counting_Bits │ │ ├── solution.go │ │ └── solution.rb │ ├── 451_Sort_Characters_By_Frequency │ │ └── solution.go │ ├── 525_Contiguous_Array │ │ ├── solution.go │ │ └── solution.py │ ├── 886_Possible_Bipartition │ │ └── solution.go │ └── 986_Interval_List_Intersections │ │ └── solution.go │ └── Week_5:_May_29th–May_31st │ ├── 207_Course_Schedule │ └── solution.go │ ├── 72_Edit_Distance │ └── Solution.cpp │ └── 973_K_Closest_Points_to_Origin │ └── solution.go ├── Concurrency ├── 1114_Print_in_Order │ └── Foo.java ├── 1115_Print_FooBar_Alternately │ └── FooBar.java └── 1195_Fizz_Buzz_Multithreaded │ └── FizzBuzz.java ├── Database ├── 1050_Actors_and_Directors_Who_Cooperated_At_Least_Three_Times │ └── solution.sql ├── 1084_Sales_Analysis_III │ └── solution.sql ├── 1141_User_Activity_for_the_Past_30_Days_I │ └── solution.sql ├── 1148_Article_Views_I │ └── solution.sql ├── 1158_Market_Analysis_I │ └── solution.sql ├── 1179_Reformat_Department_Table │ └── solution.sql ├── 1270_All_People_Report_to_the_Given_Manager │ └── solution.sql ├── 1350_Students_With_Invalid_Departments │ └── solution.sql ├── 1355_Activity_Participants │ └── solution.sql ├── 1393_Capita_ Gain_Loss │ └── solution.sql ├── 1407_Top_Travellers │ └── solution.sql ├── 1445_Apples_&_Oranges │ └── solution.sql ├── 1479_Sales_by_Day_of_the_Week │ └── solution.sql ├── 1484_Group_Sold_Products_By_The_Date │ └── solution.sql ├── 1527_Patients_With_a_Condition │ └── solution.sql ├── 1581_Customer_Who_Visited_but_Did_Not_Make_Any_Transactions │ └── solution.sql ├── 1587_Bank_Account_Summary_II │ └── solution.sql ├── 1667_Fix_Names_in_a_Table │ └── solution.sql ├── 1693_Daily_Leads_and_Partners │ └── solution.sql ├── 1729_Find_Followers_Count │ └── solution.sql ├── 1741_Find_Total_Time_Spent_by_Each_Employee │ └── solution.sql ├── 1757_Recyclable_and_Low_Fat_Products │ └── solution.sql ├── 175_Combine_Two_Tables │ └── solution.sql ├── 176_Second_Highest_Salary │ └── solution.sql ├── 177_Nth_Highest_Salary │ └── solution.sql ├── 178_Rank_Scores │ ├── solution-mysql.sql │ └── solution-oracle.sql ├── 1795_Rearrange_Products_Table │ └── solution.sql ├── 180_Consecutive_Numbers │ └── solution.sql ├── 181_Employees_Earning_More_Than_Their_Managers │ └── solution.sql ├── 182_Duplicate_Emails │ └── solution.sql ├── 183_Customers_Who_Never_Order │ └── solution.sql ├── 184_Department_Highest_Salary │ └── solution.sql ├── 185_Department_Top_Three_Salaries │ └── solution.sql ├── 1873_Calculate_Special_Bonus │ └── solution.sql ├── 1890_The_Latest_Login_in_2020 │ └── solution.sql ├── 1965_Employees_With_Missing_Information │ └── solution.sql ├── 197_Rising_Temperature │ └── solution.sql ├── 262_Trips_and_Users │ └── solution.sql ├── 511_Game_Play_Analysis_I │ └── solution.sql ├── 584_Find_Customer_Referee │ └── solution.sql ├── 586_Customer_Placing_the_Largest_Number_of_Orders │ └── solution.sql ├── 595_Big_Countries │ └── solution.sql ├── 596_Classes_More_Than_5_Students │ └── solution.sql ├── 601_Human_Traffic_of_Stadium │ └── solution.sql ├── 607_Sales_Person │ └── solution.sql ├── 608_Tree_Node │ └── solution.sql ├── 615_Average_Salary:_Departments_VS_Company │ └── solution.sql ├── 620_Not_Boring_Movies │ └── solution.sql ├── 626_Exchange_Seats │ └── solution.sql └── 627_Swap_Salary │ └── solution.sql ├── LICENSE ├── README.md ├── Shell ├── 192_Word_Frequency │ └── solution.sh ├── 193_Valid_Phone_Numbers │ └── solution.sh ├── 194_Transpose_File │ └── solution.sh └── 195_Tenth_Line │ └── solution.sh ├── analysis ├── __init__.py ├── __main__.py ├── job │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-310.pyc │ │ └── job.cpython-310.pyc │ ├── job.py │ ├── language_statistics.py │ └── leetcode_ranking.py ├── logger │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-310.pyc │ │ └── logger.cpython-310.pyc │ └── logger.py ├── output │ ├── language_statistics.png │ ├── leetcode_rankings.csv │ └── ranking_graph.png ├── service │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-310.pyc │ │ ├── github.cpython-310.pyc │ │ ├── leetcode.cpython-310.pyc │ │ └── line.cpython-310.pyc │ ├── github.py │ ├── leetcode.py │ └── line.py ├── util │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-310.pyc │ │ ├── dateutils.cpython-310.pyc │ │ └── encodingutils.cpython-310.pyc │ ├── dateutils.py │ └── encodingutils.py └── vo │ ├── __init__.py │ ├── __pycache__ │ ├── __init__.cpython-310.pyc │ ├── emoji.cpython-310.pyc │ └── message.cpython-310.pyc │ ├── emoji.py │ └── message.py └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | **/.idea/** 2 | .statistics/*.png 3 | **/*.iml 4 | analysis/output 5 | **/__pycache__ -------------------------------------------------------------------------------- /Algorithms/1004_Max_Consecutive_Ones_III/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int longestOnes(int[] A, int K) { 3 | int i = 0, j = 0; 4 | for (; j < A.length; ++j) { 5 | if (A[j] == 0) { 6 | --K; 7 | } 8 | if (K < 0) { 9 | if (A[i++] == 0) { 10 | ++K; 11 | } 12 | } 13 | } 14 | return j - i; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Algorithms/1009_Complement_of_Base_10_Integer/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def bitwiseComplement(N: Int): Int = if (N == 0) 1 else { 3 | var i = 1 4 | while (i <= N) i <<= 1 5 | N ^ (i - 1) 6 | } 7 | } -------------------------------------------------------------------------------- /Algorithms/1010_Pairs_of_Songs_With_Total_Durations_Divisible_by_60/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func p(n int) int { 4 | k := 0 5 | for i := n - 1; i > 0; i-- { 6 | k += i 7 | } 8 | return k 9 | } 10 | 11 | func numPairsDivisibleBy60(time []int) int { 12 | rem := make([]int, 61, 61) 13 | for _, t := range time { 14 | rem[t%60]++ 15 | } 16 | 17 | acc := 0 18 | for i := 1; i < 30; i++ { 19 | acc += rem[i] * rem[60-i] 20 | } 21 | 22 | return p(rem[0]) + acc + p(rem[30]) 23 | } -------------------------------------------------------------------------------- /Algorithms/1029_Two_City_Scheduling/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "sort" 4 | 5 | func twoCitySchedCost(costs [][]int) int { 6 | sort.Slice(costs, func(i, j int) bool { 7 | return costs[i][0]-costs[i][1] < costs[j][0]-costs[j][1] 8 | }) 9 | 10 | minCost, half := 0, len(costs)>>1 11 | for i := 0; i < len(costs); i++ { 12 | minCost += costs[i][i/half] 13 | } 14 | return minCost 15 | } 16 | -------------------------------------------------------------------------------- /Algorithms/1046_Last_Stone_Weight/solution.py: -------------------------------------------------------------------------------- 1 | from typing import * 2 | import heapq 3 | 4 | 5 | class Solution: 6 | def lastStoneWeight(self, stones: List[int]) -> int: 7 | pq = [-s for s in stones] 8 | heapq.heapify(pq) 9 | while len(pq) > 1: 10 | heapq.heappush(pq, -abs(heapq.heappop(pq) - heapq.heappop(pq))) 11 | return -pq[0] if pq else 0 12 | -------------------------------------------------------------------------------- /Algorithms/1047_Remove_All_Adjacent_Duplicates_In_String/solution.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | char* removeDuplicates(char* S){ 6 | int k = 0, n = strlen(S); 7 | char* stk = malloc(200001); 8 | 9 | for (int i = 0; i < n; i++) { 10 | if (k > 0 && S[i] == stk[k - 1]) { 11 | k--; 12 | } else { 13 | stk[k++] = S[i]; 14 | } 15 | } 16 | stk[k] = NULL; 17 | 18 | return stk; 19 | } 20 | -------------------------------------------------------------------------------- /Algorithms/1051_Height_Checker/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Solution { 7 | public: 8 | int heightChecker(vector& heights) { 9 | vector sorted(heights); 10 | sort(sorted.begin(), sorted.end()); 11 | 12 | int count = 0; 13 | for (int i = 0; i < sorted.size(); i++) { 14 | count += heights[i] != sorted[i]; 15 | } 16 | 17 | return count; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /Algorithms/1060_Missing_Element_in_Sorted_Array/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def missingElement(nums: Array[Int], k: Int): Int = { 3 | var n = k 4 | for (i <- Range(1, nums.length)) { 5 | val d = nums(i) - nums(i - 1) - 1 6 | if (n > d) n -= d 7 | else return nums(i - 1) + n 8 | } 9 | nums.last + n 10 | } 11 | } -------------------------------------------------------------------------------- /Algorithms/1086_High_Five/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def highFive(items: Array[Array[Int]]): Array[Array[Int]] = items 3 | .sortBy(a => -a(1)) 4 | .groupMap(_ (0))(_ (1)) 5 | .map(xs => (xs._1, xs._2.take(5))) 6 | .map(xs => Array(xs._1, xs._2.sum / 5)) 7 | .toArray 8 | .sortBy(_ (0)) 9 | } -------------------------------------------------------------------------------- /Algorithms/1108_Defanging_an_IP_Address/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {String} address 2 | # @return {String} 3 | def defang_i_paddr(address) 4 | address.gsub('.', '[.]') 5 | end -------------------------------------------------------------------------------- /Algorithms/1119_Remove_Vowels_from_a_String/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def removeVowels(S: String): String = (for (s <- S) yield s match { 3 | case 'a' | 'e' | 'i' | 'o' | 'u' => "" 4 | case _ => s 5 | }).foldLeft("")(_ + _) 6 | } -------------------------------------------------------------------------------- /Algorithms/1133_Largest_Unique_Number/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int largestUniqueNumber(int[] A) { 3 | int[] cnt = new int[1001]; 4 | for (int a : A) { 5 | ++cnt[a]; 6 | } 7 | for (int i = cnt.length - 1; i >= 0; --i) { 8 | if (cnt[i] == 1) { 9 | return i; 10 | } 11 | } 12 | return -1; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Algorithms/1154_Day_of_the_Year/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @github https://github.com/occidere 4 | * @blog https://blog.naver.com/occidere 5 | * @since 2022-12-09 6 | */ 7 | class Solution { 8 | fun dayOfYear(date: String) = java.time.LocalDate.parse(date).dayOfYear 9 | } 10 | -------------------------------------------------------------------------------- /Algorithms/1165_Single-Row_Keyboard/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def calculateTime(keyboard: String, word: String): Int = word.foldLeft((keyboard(0), 0))((t, c) => (c, t._2 + (keyboard.indexOf(t._1) - keyboard.indexOf(c)).abs))._2 3 | } -------------------------------------------------------------------------------- /Algorithms/1167_Minimum_Cost_to_Connect_Sticks/Solution.scala: -------------------------------------------------------------------------------- 1 | import scala.collection.mutable 2 | 3 | object Solution { 4 | def connectSticks(sticks: Array[Int]): Int = { 5 | val minHeap = sticks.foldLeft(mutable.PriorityQueue[Int]())(_ += -_) 6 | var (acc, a) = 0 -> minHeap.dequeue() 7 | while (minHeap.nonEmpty) { 8 | a += minHeap.dequeue() 9 | acc += a 10 | minHeap.enqueue(a) 11 | a = minHeap.dequeue() 12 | } 13 | -acc 14 | } 15 | } -------------------------------------------------------------------------------- /Algorithms/118_Pascal's_Triangle/solution.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | 4 | class Solution: 5 | def generate(self, numRows: int) -> List[List[int]]: 6 | rows: List[List[int]] = [[1]] 7 | for i in range(1, numRows): 8 | rows.append([1] + [(rows[i - 1][j - 1] + rows[i - 1][j]) for j in range(1, len(rows[i - 1]))] + [1]) 9 | return [] if numRows == 0 else rows 10 | -------------------------------------------------------------------------------- /Algorithms/1198_Find_Smallest_Common_Element_in_All_Rows/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun smallestCommonElement(mat: Array): Int { 3 | var commons = mat[0].toSet() 4 | for (m in mat.drop(1)) { 5 | val c = commons.intersect(m.toSet()) 6 | if (c.isEmpty()) return -1 else commons = c 7 | } 8 | return commons.sorted()[0] 9 | } 10 | } -------------------------------------------------------------------------------- /Algorithms/119_Pascal's_Triangle_II/solution.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | 4 | class Solution: 5 | def getRow(self, rowIndex: int) -> List[int]: 6 | a, b = [1], [] 7 | for i in range(1, rowIndex + 1): 8 | b = [1] + [(a[j - 1] + a[j]) for j in range(1, len(a))] + [1] 9 | a = b 10 | return a 11 | -------------------------------------------------------------------------------- /Algorithms/11_Container_With_Most_Water/Solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxArea(self, height: List[int]) -> int: 3 | max_area, l, r = 0, 0, len(height) - 1 4 | while l < r: 5 | max_area = max(max_area, (r - l) * min(height[l], height[r])) 6 | l, r = (l + 1, r) if height[l] < height[r] else (l, r - 1) 7 | return max_area 8 | -------------------------------------------------------------------------------- /Algorithms/1200_Minimum_Absolute_Difference/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-08-20 6 | */ 7 | class Solution { 8 | fun minimumAbsDifference(arr: IntArray): List> = arr.sorted() 9 | .zipWithNext() 10 | .map { kotlin.math.abs(it.first - it.second) to listOf(it.first, it.second) } 11 | .groupBy({ it.first }) { it.second } 12 | .toSortedMap() 13 | .values 14 | .first() 15 | } 16 | -------------------------------------------------------------------------------- /Algorithms/1209_Remove_All_Adjacent_Duplicates_in_String_II/solution.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | 4 | class Solution: 5 | def removeDuplicates(self, s: str, k: int) -> str: 6 | stk: List[(str, int)] = [] 7 | for c in s: 8 | top, freq = ('', 0) if not stk else stk[-1] 9 | stk.append((c, 1 + (freq if c == top else 0))) 10 | while len(stk) >= k and stk[-1][1] == k: 11 | stk = stk[:-k] 12 | return ''.join([x for x, _ in stk]) 13 | -------------------------------------------------------------------------------- /Algorithms/1213_Intersection_of_Three_Sorted_Arrays/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun arraysIntersection(arr1: IntArray, arr2: IntArray, arr3: IntArray): List = 3 | arr1.toSet().intersect(arr2.toSet()).intersect(arr3.toSet()).toList() 4 | } 5 | 6 | -------------------------------------------------------------------------------- /Algorithms/1217_Minimum_Cost_to_Move_Chips_to_The_Same_Position/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun minCostToMoveChips(position: IntArray) = position.map { it.rem(2) to (it + 1).rem(2) } 3 | .reduce { acc, p -> Pair(acc.first + p.first, acc.second + p.second) } 4 | .run { kotlin.math.min(first, second) } 5 | } 6 | -------------------------------------------------------------------------------- /Algorithms/121_Best_Time_to_Buy_and_Sell_Stock/solution.py: -------------------------------------------------------------------------------- 1 | from typing import * 2 | 3 | 4 | class Solution: 5 | def maxProfit(self, prices: List[int]) -> int: 6 | if not prices: 7 | return 0 8 | max_profit, min_price = 0, prices[0] 9 | for p in prices[1:]: 10 | max_profit, min_price = max(max_profit, p - min_price), min(min_price, p) 11 | return max_profit 12 | -------------------------------------------------------------------------------- /Algorithms/122_Best_Time_to_Buy_and_Sell_Stock_II/solution.py: -------------------------------------------------------------------------------- 1 | from typing import * 2 | 3 | 4 | class Solution: 5 | def maxProfit(self, prices: List[int]) -> int: 6 | max_profit = 0 7 | for i in range(1, len(prices)): 8 | max_profit += prices[i] - prices[i - 1] if prices[i] > prices[i - 1] else 0 9 | return max_profit 10 | -------------------------------------------------------------------------------- /Algorithms/1232_Check_If_It_Is_a_Straight_Line/solution.py: -------------------------------------------------------------------------------- 1 | from typing import * 2 | 3 | 4 | class Solution: 5 | def checkStraightLine(self, coordinates: List[List[int]]) -> bool: 6 | (x0, y0), (x1, y1) = coordinates[:2] 7 | return all((x1 - x0) * (y - y1) == (x - x1) * (y1 - y0) for x, y in coordinates) 8 | -------------------------------------------------------------------------------- /Algorithms/1249_Minimum_Remove_to_Make_Valid_Parentheses/Solution.scala: -------------------------------------------------------------------------------- 1 | import scala.collection.mutable 2 | 3 | object Solution { 4 | def minRemoveToMakeValid(s: String): String = { 5 | val cs = s.split("") 6 | val stk = mutable.Stack[Int]() 7 | for (i <- cs.indices) cs(i) match { 8 | case "(" => stk.push(i) 9 | case ")" => if (stk.isEmpty) cs(i) = "" else stk.pop() 10 | case _ => 11 | } 12 | stk.popAll().foreach(cs(_) = "") 13 | cs.mkString("") 14 | } 15 | } -------------------------------------------------------------------------------- /Algorithms/125_Valid_Palindrome/solution.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | class Solution: 5 | def isPalindrome(self, s: str) -> bool: 6 | s = re.sub('[^a-z0-9]', '', s.lower()) 7 | return s == s[::-1] 8 | -------------------------------------------------------------------------------- /Algorithms/1281_Subtract_the_Product_and_Sum_of_Digits_of_an_Integer/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int subtractProductAndSum(int n) { 8 | int a = 1, b = 0; 9 | for (char& c : to_string(n)) { 10 | a *= (c - 48); 11 | b += (c - 48); 12 | } 13 | return a - b; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /Algorithms/1287_Element_Appearing_More_Than_25%_In_Sorted_Array/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-11-12 6 | */ 7 | class Solution { 8 | fun findSpecialInteger(arr: IntArray) = arr.groupBy { it } 9 | .asSequence() 10 | .map { it.key to it.value.size } 11 | .maxBy { it.second }!! 12 | .first 13 | } 14 | -------------------------------------------------------------------------------- /Algorithms/1291_Sequential_Digits/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun sequentialDigits(low: Int, high: Int) = "123456789".run { 3 | (1..9).flatMap { w -> 4 | (0..9 - w).map { i -> 5 | substring(i, i + w).toInt().let { if (it in low..high) it else 0 } 6 | } 7 | } 8 | }.filter { it != 0 } 9 | } 10 | -------------------------------------------------------------------------------- /Algorithms/1295_Find_Numbers_with_Even_Number_of_Digits/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Solution { 7 | public: 8 | int findNumbers(vector& nums) { 9 | int count = 0; 10 | 11 | for (int i = 0; i < nums.size(); i++) { 12 | if (to_string(nums[i]).length() % 2 == 0) { 13 | count++; 14 | } 15 | } 16 | 17 | return count; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /Algorithms/1299_Replace_Elements_with_Greatest_Element_on_Right_Side/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | vector replaceElements(vector& arr) { 8 | vector ans({-1}); 9 | int m = -1; 10 | for (int i = arr.size() - 1; i > 0; i--) { 11 | m = m < arr[i] ? arr[i] : m; 12 | ans.push_back(m); 13 | } 14 | reverse(ans.begin(), ans.end()); 15 | return ans; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /Algorithms/1304_Find_N_Unique_Integers_Sum_up_to_Zero/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | vector sumZero(int n) { 8 | vector ans; 9 | 10 | for (int i = 1; i < n; i += 2) { 11 | ans.push_back(i); 12 | ans.push_back(-i); 13 | } 14 | 15 | if (n % 2) { 16 | ans.push_back(0); 17 | } 18 | 19 | return ans; 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /Algorithms/1309_Decrypt_String_from_Alphabet_to_Integer_Mapping/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def freqAlphabets(self, s: str) -> str: 3 | s, ans = s[::-1], '' 4 | i, n = 0, len(s) 5 | while i < n: 6 | if s[i] == '#': 7 | ans += chr(int(s[i + 2] + s[i + 1]) + 96) 8 | i += 3 9 | else: 10 | ans += chr(int(s[i]) + 96) 11 | i += 1 12 | return ans[::-1] 13 | -------------------------------------------------------------------------------- /Algorithms/1313_Decompress_Run-Length_Encoded_List/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | vector decompressRLElist(vector& nums) { 8 | vector ans; 9 | for (int i = 1; i < nums.size(); i += 2) { 10 | for (int j = 0; j < nums[i - 1]; j++) { 11 | ans.push_back(nums[i]); 12 | } 13 | } 14 | return ans; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /Algorithms/1323_Maximum_69_Number/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int maximum69Number (int num) { 8 | string ans = to_string(num); 9 | for (int i = 0; i < ans.size(); i++) { 10 | if (ans[i] == '6') { 11 | ans[i] = '9'; 12 | break; 13 | } 14 | } 15 | return stoi(ans); 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /Algorithms/1324_Print_Words_Vertically/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun printVertically(s: String) = s.split(" ").toTypedArray().run { 3 | 0.until(map { it.length }.max()!!) 4 | .map { i -> 5 | indices.map { j -> if (i < this[j].length) this[j][i] else ' ' } 6 | .joinToString("") 7 | .trimEnd() 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Algorithms/1331_Rank_Transform_of_an_Array/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2023-01-01 6 | */ 7 | class Solution { 8 | fun arrayRankTransform(arr: IntArray): IntArray { 9 | val rankMap = arr.asSequence() 10 | .toSortedSet() 11 | .withIndex() 12 | .associate { (i, x) -> x to i + 1 } 13 | return arr.map { rankMap[it]!! }.toIntArray() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Algorithms/1333_Filter_Restaurants_by_Vegan-Friendly,_Price_and_Distance/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def filterRestaurants(restaurants: Array[Array[Int]], veganFriendly: Int, maxPrice: Int, maxDistance: Int): List[Int] = 3 | restaurants.filter(veganFriendly == 0 || _(2) == veganFriendly) 4 | .filter(x => x(3) <= maxPrice && x(4) <= maxDistance) 5 | .sortWith((x, y) => if (x(1) == y(1)) x.head > y.head else x(1) > y(1)) 6 | .map(_.head) 7 | .toList 8 | } -------------------------------------------------------------------------------- /Algorithms/1338_Reduce_Array_Size_to_The_Half/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun minSetSize(arr: IntArray): Int { 3 | var acc = 0 4 | return 1 + arr.fold(mutableMapOf(), { m, n -> m.merge(n, 1, Integer::sum); m }) 5 | .values 6 | .sortedWith(Comparator { a, b -> b.compareTo(a) }) 7 | .map { acc += it; acc } 8 | .takeWhile { it < arr.size shr 1 } 9 | .count() 10 | } 11 | } -------------------------------------------------------------------------------- /Algorithms/1342_Number_of_Steps_to_Reduce_a_Number_to_Zero/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Solution { 5 | public: 6 | int numberOfSteps (int num) { 7 | int c; 8 | for (c = 0; num; c += (num & 1) ? 2 : 1, num >>= 1); 9 | return c - 1; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /Algorithms/1344_Angle_Between_Hands_of_a_Clock/Solution.kt: -------------------------------------------------------------------------------- 1 | import kotlin.math.abs 2 | import kotlin.math.min 3 | 4 | class Solution { 5 | fun angleClock(hour: Int, minutes: Int): Double = 6 | abs(minutes * 6 - (hour * 60 + minutes) * .5).let { min(it, abs(360 - it)) } 7 | } -------------------------------------------------------------------------------- /Algorithms/1346_Check_If_N_and_Its_Double_Exist/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @github https://github.com/occidere 4 | * @blog https://blog.naver.com/occidere 5 | * @since 2022-07-12 6 | */ 7 | class Solution { 8 | fun checkIfExist(arr: IntArray): Boolean { 9 | for (i in arr.indices) { 10 | for (j in arr.indices) { 11 | if (i != j && arr[i].shl(1) == arr[j]) { 12 | return true 13 | } 14 | } 15 | } 16 | return false 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Algorithms/1351_Count_Negative_Numbers_in_a_Sorted_Matrix/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int countNegatives(vector>& grid) { 8 | int c = 0, m = grid.size(), n = grid[0].size(); 9 | for (int i = 0; i < m; i++) { 10 | for (int j = 0; j < n; j++) { 11 | if (grid[i][j] < 0) { 12 | c += n - j; 13 | break; 14 | } 15 | } 16 | } 17 | return c; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /Algorithms/1356_Sort_Integers_by_The_Number_of_1_Bits/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} arr 3 | * @return {number[]} 4 | */ 5 | const sortByBits = function (arr) { 6 | return arr.sort((x, y) => { 7 | const numberOfOneBits = (dec) => dec.toString(2) 8 | .split("") 9 | .map(c => c - '0') 10 | .reduce((a, b) => a + b, 0); 11 | const [a, b] = [numberOfOneBits(x), numberOfOneBits(y)]; 12 | return a === b ? x - y : a - b; 13 | }); 14 | }; 15 | -------------------------------------------------------------------------------- /Algorithms/1358_Number_of_Substrings_Containing_All_Three_Characters/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun numberOfSubstrings(s: String) = intArrayOf(-1, -1, -1).run { 3 | s.indices.map { 4 | this[s[it] - 'a'] = it 5 | getCount() 6 | }.sum() 7 | } 8 | 9 | private fun IntArray.getCount() = if (this[0] >= 0 && this[1] >= 0 && this[2] >= 0) min()!! + 1 else 0 10 | } 11 | -------------------------------------------------------------------------------- /Algorithms/1365_How_Many_Numbers_Are_Smaller_Than_the_Current_Number/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | vector smallerNumbersThanCurrent(vector& nums) { 8 | vector ans(nums.size()); 9 | for (int i = 0; i < nums.size(); ++i) { 10 | for (int j = 0; j < nums.size(); ++j) { 11 | ans[i] += nums[j] < nums[i]; 12 | } 13 | } 14 | return ans; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /Algorithms/136_Single_Number/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int singleNumber(int[] nums) { 3 | int a = 0; 4 | for (int num : nums) { 5 | a ^= num; 6 | } 7 | return a; 8 | } 9 | } -------------------------------------------------------------------------------- /Algorithms/136_Single_Number/solution.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | 4 | class Solution: 5 | def singleNumber(self, nums: List[int]) -> int: 6 | b = 0 7 | for k in nums: 8 | b ^= k 9 | return b 10 | -------------------------------------------------------------------------------- /Algorithms/136_Single_Number/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Integer} 3 | def single_number(nums) 4 | a = 0 5 | nums.each { |n| a ^= n } 6 | a 7 | end -------------------------------------------------------------------------------- /Algorithms/1374_Generate_a_String_With_Characters_That_Have_Odd_Counts/solution.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * generateTheString(int n){ 5 | char* s = malloc(n * 500); 6 | if (n % 2 == 0) { 7 | s[0] = 'a'; 8 | } 9 | for (int i = (n % 2 == 0); i < n; s[i++] = 'b'); 10 | s[n] = NULL; 11 | return s; 12 | } 13 | -------------------------------------------------------------------------------- /Algorithms/137_Single_Number_II/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | // https://leetcode.com/problems/single-number-ii/solution/ 3 | public int singleNumber(int[] nums) { 4 | int once = 0, twice = 0; 5 | for (int n : nums) { 6 | once = ~twice & (once ^ n); 7 | twice = ~once & (twice ^ n); 8 | } 9 | return once; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/1381_Design_a_Stack_With_Increment_Operation/CustomStack.kt: -------------------------------------------------------------------------------- 1 | class CustomStack(private val maxSize: Int) { 2 | private var size = 0 3 | private val stk = IntArray(maxSize) 4 | 5 | fun push(x: Int) { 6 | if (size < maxSize) { 7 | stk[size++] = x 8 | } 9 | } 10 | 11 | fun pop(): Int = if (size > 0) stk[--size] else -1 12 | 13 | fun increment(k: Int, `val`: Int) = 0.until(Integer.min(size, k)).forEach { stk[it] += `val` } 14 | } -------------------------------------------------------------------------------- /Algorithms/1381_Design_a_Stack_With_Increment_Operation/CustomStack.scala: -------------------------------------------------------------------------------- 1 | class CustomStack(_maxSize: Int) { 2 | 3 | private var size = 0 4 | private val stk = Array.fill(_maxSize)(0) 5 | 6 | def push(x: Int): Unit = if (size < _maxSize) { 7 | stk(size) = x 8 | size += 1 9 | } 10 | 11 | def pop(): Int = if (size == 0) -1 else { 12 | size -= 1 13 | stk(size) 14 | } 15 | 16 | def increment(k: Int, `val`: Int): Unit = Range(0, math.min(k, size)).foreach(stk(_) += `val`) 17 | 18 | } -------------------------------------------------------------------------------- /Algorithms/1389_Create_Target_Array_in_the_Given_Order/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func createTargetArray(nums []int, index []int) []int { 4 | n := len(nums) 5 | ans := make([]int, n, n) 6 | for i := 0; i < n; i++ { 7 | p := index[i] 8 | for j := i; j > p; j-- { 9 | ans[j] = ans[j-1] 10 | } 11 | ans[p] = nums[i] 12 | } 13 | return ans 14 | } -------------------------------------------------------------------------------- /Algorithms/1394_Find_Lucky_Integer_in_an_Array/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @github https://github.com/occidere 4 | * @blog https://blog.naver.com/occidere 5 | * @since 2022-11-28 6 | */ 7 | class Solution { 8 | fun findLucky(arr: IntArray) = arr.groupBy { it } 9 | .asSequence() 10 | .filter { it.key == it.value.size } 11 | .map { it.key } 12 | .sorted() 13 | .lastOrNull() ?: -1 14 | } 15 | -------------------------------------------------------------------------------- /Algorithms/1395_Count_Number_of_Teams/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func numTeams(rating []int) int { 4 | n, ans := len(rating), 0 5 | for i := 0; i < n-2; i++ { 6 | for j := i + 1; j < n-1; j++ { 7 | for k := j + 1; k < n; k++ { 8 | if (rating[i] < rating[j] && rating[j] < rating[k]) || (rating[i] > rating[j] && rating[j] > rating[k]) { 9 | ans++ 10 | } 11 | } 12 | } 13 | } 14 | return ans 15 | } 16 | -------------------------------------------------------------------------------- /Algorithms/1399_Count_Largest_Group/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-08-27 6 | */ 7 | class Solution { 8 | fun countLargestGroup(n: Int) = (1..n).groupBy { it.toString().sumBy { c -> c - '0' } } 9 | .map { it.value.size } 10 | .groupBy { it } 11 | .maxBy { it.key } 12 | ?.value 13 | ?.size ?: -1 14 | } 15 | -------------------------------------------------------------------------------- /Algorithms/1409_Queries_on_a_Permutation_With_Key/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def processQueries(queries: Array[Int], m: Int): Array[Int] = { 3 | val p = List.range(1, m + 1).toBuffer 4 | Array.range(0, queries.length).map(i => (p.takeWhile(_ != queries(i)).distinct.length, p.insert(0, queries(i)))._1) 5 | } 6 | } -------------------------------------------------------------------------------- /Algorithms/1431_Kids_With_the_Greatest_Number_of_Candies/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func Max(a, b int) int { 4 | if a < b { 5 | return b 6 | } else { 7 | return a 8 | } 9 | } 10 | 11 | func kidsWithCandies(candies []int, extraCandies int) []bool { 12 | ans := make([]bool, len(candies), len(candies)) 13 | 14 | max := 0 15 | for _, c := range candies { 16 | max = Max(max, c) 17 | } 18 | 19 | for i, c := range candies { 20 | if c + extraCandies >= max { 21 | ans[i] = true 22 | } 23 | } 24 | 25 | return ans 26 | } -------------------------------------------------------------------------------- /Algorithms/1436_Destination_City/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func destCity(paths [][]string) string { 4 | path := make(map[string]string) 5 | for _, p := range paths { 6 | path[p[0]] = p[1] 7 | } 8 | for _, v := range path { 9 | if path[v] == "" { 10 | return v 11 | } 12 | } 13 | return "" 14 | } -------------------------------------------------------------------------------- /Algorithms/1437_Check_If_All_1s_Are_at_Least_Length_K_Places_Away/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun kLengthApart(nums: IntArray, k: Int): Boolean = nums.zip(nums.indices) 3 | .filter { it.first == 1 } 4 | .map { it.second } 5 | .run { 6 | this.isEmpty() || this.zipWithNext().find { it.second - it.first - 1 < k } == null 7 | } 8 | } -------------------------------------------------------------------------------- /Algorithms/1437_Check_If_All_1s_Are_at_Least_Length_K_Places_Away/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def kLengthApart(nums: Array[Int], k: Int): Boolean = { 3 | val arr = nums.zipWithIndex 4 | .filter(_._1 == 1) 5 | .map(_._2) 6 | arr.isEmpty || !arr.zip(arr.tail).exists(x => x._2 - x._1 - 1 < k) 7 | } 8 | } -------------------------------------------------------------------------------- /Algorithms/1450_Number_of_Students_Doing_Homework_at_a_Given_Time/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func busyStudent(startTime []int, endTime []int, queryTime int) int { 4 | ans := 0 5 | for i := 0; i < len(startTime); i++ { 6 | if startTime[i] <= queryTime && queryTime <= endTime[i] { 7 | ans++ 8 | } 9 | } 10 | return ans 11 | } -------------------------------------------------------------------------------- /Algorithms/1451_Rearrange_Words_in_a_Sentence/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun arrangeWords(text: String) = text.split(" ") 3 | .let { it.zip(it.indices) } 4 | .sortedWith(Comparator { x, y -> if (x.first.length == y.first.length) x.second - y.second else x.first.length - y.first.length }) 5 | .map { it.first } 6 | .let { it.zip(it.indices) } 7 | .joinToString(" ") { if (it.second == 0) it.first.capitalize() else it.first.toLowerCase() } 8 | } 9 | -------------------------------------------------------------------------------- /Algorithms/1455_Check_If_a_Word_Occurs_As_a_Prefix_of_Any_Word_in_a_Sentence/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @github https://github.com/occidere 4 | * @blog https://blog.naver.com/occidere 5 | * @since 2022-11-17 6 | */ 7 | class Solution { 8 | fun isPrefixOfWord(sentence: String, searchWord: String) = sentence.split(" ") 9 | .asSequence() 10 | .withIndex() 11 | .filter { (_, v) -> v.startsWith(searchWord) } 12 | .map { it.index + 1 } 13 | .min() ?: -1 14 | } 15 | -------------------------------------------------------------------------------- /Algorithms/1460_Make_Two_Arrays_Equal_by_Reversing_Sub-arrays/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "sort" 4 | 5 | func canBeEqual(target []int, arr []int) bool { 6 | sort.Ints(target) 7 | sort.Ints(arr) 8 | for i := 0; i < len(arr); i++ { 9 | if arr[i] != target[i] { 10 | return false 11 | } 12 | } 13 | return true 14 | } 15 | 16 | func main() { 17 | // 2, 3, 1, 4 18 | // 2, 1, 3, 4 19 | // 1, 2, 3, 4 20 | } -------------------------------------------------------------------------------- /Algorithms/1461_Check_If_a_String_Contains_All_Binary_Codes_of_Size_K/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def hasAllCodes(s: String, k: Int): Boolean = { 3 | val bins = (k to s.length).map(i => s.substring(i - k, i)).toSet 4 | for (i <- 0 to (math.pow(2, k) - 1).toInt) { 5 | if (!bins.contains(s"%${k}s".format(i.toBinaryString).replace(" ", "0"))) { 6 | return false 7 | } 8 | } 9 | true 10 | } 11 | } -------------------------------------------------------------------------------- /Algorithms/1464_Maximum_Product_of_Two_Elements_in_an_Array/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "sort" 4 | 5 | func maxProduct(nums []int) int { 6 | sort.Slice(nums, func(i, j int) bool { 7 | return nums[i] > nums[j] 8 | }) 9 | return (nums[0] - 1) * (nums[1] - 1) 10 | } 11 | -------------------------------------------------------------------------------- /Algorithms/1470_Shuffle_the_Array/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func shuffle(nums []int, n int) []int { 4 | var ans []int 5 | for i := 0; i < n; i++ { 6 | ans = append(ans, nums[i], nums[i+n]) 7 | } 8 | return ans 9 | } 10 | -------------------------------------------------------------------------------- /Algorithms/1475_Final_Prices_With_a_Special_Discount_in_a_Shop/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun finalPrices(prices: IntArray) = prices.indices.map { i -> 3 | (i + 1).until(prices.size) 4 | .find { j -> prices[j] <= prices[i] }?.let { 5 | prices[i] - prices[it] 6 | } ?: prices[i] 7 | }.toIntArray() 8 | } 9 | -------------------------------------------------------------------------------- /Algorithms/1480_Running_Sum_of_1d_Array/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func runningSum(nums []int) []int { 4 | for i := 1; i < len(nums); i++ { 5 | nums[i] += nums[i-1] 6 | } 7 | return nums 8 | } 9 | -------------------------------------------------------------------------------- /Algorithms/1481_Least_Number_of_Unique_Integers_after_K_Removals/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def findLeastNumOfUniqueInts(arr: Array[Int], k: Int): Int = { 3 | var r = k 4 | arr.groupMapReduce(x => x)(_ => 1)(_ + _) 5 | .toList 6 | .sortBy(_._2) 7 | .dropWhile(x => {r -= x._2; r >= 0}) 8 | .size 9 | } 10 | } -------------------------------------------------------------------------------- /Algorithms/1486_XOR_Operation_in_an_Array/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def xorOperation(n: Int, start: Int): Int = LazyList range(0, n) map(i => start + 2 * i) reduce(_ ^ _) 3 | } -------------------------------------------------------------------------------- /Algorithms/1490_Clone_N-ary_Tree/Solution.scala: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a Node. 3 | * class Node(var _value: Int) { 4 | * var value: Int = _value 5 | * var children: List[Node] = List() 6 | * } 7 | */ 8 | 9 | object Solution { 10 | def cloneTree(root: Node): Node = if (root == null) null else new Node(root.value) { 11 | children = root.children.map(cloneTree) 12 | } 13 | } -------------------------------------------------------------------------------- /Algorithms/1491_Average_Salary_Excluding_the_Minimum_and_Maximum_Salary/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun average(salary: IntArray) = 3 | salary.sorted().drop(1).dropLast(1).average() 4 | } 5 | -------------------------------------------------------------------------------- /Algorithms/14_Longest_Common_Prefix/solution.rb: -------------------------------------------------------------------------------- 1 | def longest_common_prefix(strs) 2 | strs = strs.sort_by(&:length) 3 | lcp = strs[0] 4 | 5 | (1...strs.length).each do |i| 6 | min_len = [lcp.length, strs[i].length].min 7 | (0...min_len).each do |j| 8 | if lcp[j].chr != strs[i][j].chr 9 | lcp = j.zero? ? '' : lcp[0..j - 1] 10 | break 11 | end 12 | end 13 | end 14 | lcp.nil? ? '' : lcp 15 | end 16 | -------------------------------------------------------------------------------- /Algorithms/1502_Can_Make_Arithmetic_Progression_From_Sequence/Solution.scala: -------------------------------------------------------------------------------- 1 | import scala.collection.mutable.ListBuffer 2 | 3 | object Solution { 4 | def canMakeArithmeticProgression(arr: Array[Int]): Boolean = if (arr.length <= 2) true else { 5 | val sorted = arr.sorted 6 | val diffs = sorted.zip(sorted.tail).map(xs => xs._1 - xs._2) 7 | diffs.zip(diffs.tail) 8 | .foldLeft(ListBuffer[Int]())((lb, xs) => {lb ++= xs._1 :: xs._2 :: Nil; lb}) 9 | .distinct 10 | .length == 1 11 | } 12 | } -------------------------------------------------------------------------------- /Algorithms/1506_Find_Root_of_N-Ary_Tree/Solution.scala: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a Node. 3 | * class Node(var _value: Int) { 4 | * var value: Int = _value 5 | * var children: List[Node] = List() 6 | * } 7 | */ 8 | 9 | object Solution { 10 | def findRoot(tree: List[Node]): Node = { 11 | val rootNum = tree.map(parent => parent.value - parent.children.map(_.value).sum).sum 12 | tree.find(_.value == rootNum).head 13 | } 14 | } -------------------------------------------------------------------------------- /Algorithms/1512_Number_of_Good_Pairs/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def numIdenticalPairs(nums: Array[Int]): Int = nums 3 | .map((_, 1)) 4 | .groupMapReduce(_._1)(_._2)(_ + _) 5 | .map(kv => kv._2 * (kv._2 - 1) >> 1) 6 | .sum 7 | } -------------------------------------------------------------------------------- /Algorithms/1512_Number_of_Good_Pairs/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func numIdenticalPairs(nums []int) int { 4 | freq := make(map[int]int) 5 | for _, n := range nums { 6 | freq[n]++ 7 | } 8 | pairs := 0 9 | for _, v := range freq { 10 | pairs += v * (v - 1) >> 1 11 | } 12 | return pairs 13 | } 14 | 15 | func main() { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Algorithms/1523_Count_Odd_Numbers_in_an_Interval_Range/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun countOdds(low: Int, high: Int) = 3 | ((if (high % 2 == 0) high - 1 else high) - (if (low % 2 == 0) low + 1 else low)).shr(1) + 1 4 | } 5 | -------------------------------------------------------------------------------- /Algorithms/1528_Shuffle_String/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func restoreString(s string, indices []int) string { 4 | s2 := make([]byte, len(s), len(s)) 5 | for i, idx := range indices { 6 | s2[idx] = s[i] 7 | } 8 | return string(s2) 9 | } -------------------------------------------------------------------------------- /Algorithms/1529_Minimum_Suffix_Flips/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-09-24 6 | */ 7 | class Solution { 8 | fun minFlips(target: String): Int { 9 | var (prev, flip) = '0' to 0 10 | for (i in target.indices) { 11 | if (target[i] != prev) { 12 | prev = target[i] 13 | ++flip 14 | } 15 | } 16 | return flip 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Algorithms/1539_Kth_Missing_Positive_Number/solution.rb: -------------------------------------------------------------------------------- 1 | require 'set' 2 | 3 | # @param {Integer[]} arr 4 | # @param {Integer} k 5 | # @return {Integer} 6 | def find_kth_positive(arr, k) 7 | set, cnt = arr.uniq.to_set, 0 8 | (1..2000).each { |i| 9 | cnt += set.include?(i) ? 0 : 1 10 | if cnt == k 11 | return i 12 | end 13 | } 14 | 0 15 | end 16 | -------------------------------------------------------------------------------- /Algorithms/1550_Three_Consecutive_Odds/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-11-19 6 | */ 7 | class Solution { 8 | fun threeConsecutiveOdds(arr: IntArray) = 9 | generateSequence(listOf(0, 1, 2)) { listOf(it[0] + 1, it[1] + 1, it[2] + 1) } 10 | .takeWhile { it[2] < arr.size } 11 | .any { (x, y, z) -> arr[x] % 2 == 1 && arr[y] % 2 == 1 && arr[z] % 2 == 1 } 12 | } 13 | -------------------------------------------------------------------------------- /Algorithms/1551_Minimum_Operations_to_Make_Array_Equal/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://occidere.blog.me 4 | * @Github: https://github.com/occidere 5 | * @since 2020-12-05 6 | */ 7 | class Solution { 8 | fun minOperations(n: Int): Int = generateSequence(1, { i -> i + 2 }) 9 | .takeWhile { it < n } 10 | .map { n - it } 11 | .sum() 12 | } -------------------------------------------------------------------------------- /Algorithms/1557_Minimum_Number_of_Vertices_to_Reach_All_Nodes/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun findSmallestSetOfVertices(n: Int, edges: List>) = 3 | ((0 until n).toSet() - edges.map { it.last() }.toSet()).toList() 4 | } 5 | -------------------------------------------------------------------------------- /Algorithms/1561_Maximum_Number_of_Coins_You_Can_Get/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxCoins(int[] piles) { 3 | int ans = 0; 4 | java.util.Arrays.sort(piles); 5 | for (int i = piles.length / 3; i < piles.length; i += 2) { 6 | ans += piles[i]; 7 | } 8 | return ans; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Algorithms/1608_Special_Array_With_X_Elements_Greater_Than_or_Equal_X/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun specialArray(nums: IntArray) = nums.sorted() 3 | .run { 4 | var limit = 0 5 | for (n in 0..last()) { 6 | while (limit < size && this[limit] < n) { 7 | ++limit 8 | } 9 | if (size - limit == n) { 10 | return n 11 | } 12 | } 13 | -1 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Algorithms/1614_Maximum_Nesting_Depth_of_the_Parentheses/Solution.kt: -------------------------------------------------------------------------------- 1 | import java.util.* 2 | import kotlin.math.max 3 | 4 | class Solution { 5 | fun maxDepth(s: String): Int { 6 | var maxCount = 0 7 | var count = 0 8 | 9 | for (c in s) { 10 | if (c == '(') maxCount = max(maxCount, ++count) 11 | else if (c == ')') --count 12 | } 13 | 14 | return maxCount 15 | } 16 | } -------------------------------------------------------------------------------- /Algorithms/1619_Mean_of_Array_After_Removing_Some_Elements/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-10-18 6 | */ 7 | class Solution { 8 | fun trimMean(arr: IntArray) = arr.sorted() 9 | .run { subList((size * 0.05).toInt(), size - (size * 0.05).toInt()) } 10 | .average() 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/162_Find_Peak_Element/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func findPeakElement(nums []int) int { 4 | size := len(nums) 5 | if size == 1 || nums[0] > nums[1] { 6 | return 0 7 | } else if nums[size-2] < nums[size-1] { 8 | return size - 1 9 | } 10 | 11 | for i := 1; i < size-1; i++ { 12 | if nums[i-1] < nums[i] && nums[i] > nums[i+1] { 13 | return i 14 | } 15 | } 16 | return 0 17 | } -------------------------------------------------------------------------------- /Algorithms/1630_Arithmetic_Subarrays/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun checkArithmeticSubarrays(nums: IntArray, l: IntArray, r: IntArray): List = l.zip(r) 3 | .map { nums.slice(it.first..it.second).sorted() } 4 | .map { it.zip(it.slice(1 until it.size)) } 5 | .map { xs -> xs.map { it.first - it.second }.distinct().count() == 1 } 6 | } -------------------------------------------------------------------------------- /Algorithms/1630_Arithmetic_Subarrays/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def checkArithmeticSubarrays(nums: Array[Int], l: Array[Int], r: Array[Int]): List[Boolean] = l.zip(r) 3 | .map(xs => nums.slice(xs._1, xs._2 + 1).sorted) 4 | .map(xs => xs.zip(xs.slice(1, xs.length)) 5 | .map(ys => ys._1 - ys._2) 6 | .distinct 7 | .length == 1 8 | ).toList 9 | } -------------------------------------------------------------------------------- /Algorithms/1630_Arithmetic_Subarrays/solution.py: -------------------------------------------------------------------------------- 1 | from typing import * 2 | 3 | 4 | class Solution: 5 | def checkArithmeticSubarrays(self, nums: List[int], l: List[int], r: List[int]) -> List[bool]: 6 | return [len(set(map(lambda ys: ys[0] - ys[1], zip(xs, xs[1:])))) == 1 for xs in [sorted(nums[i:j + 1]) for i, j in zip(l, r)]] 7 | -------------------------------------------------------------------------------- /Algorithms/1636_Sort_Array_by_Increasing_Frequency/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun frequencySort(nums: IntArray) = nums.groupBy { it } 3 | .map { it.key to it.value.size } 4 | .sortedWith(Comparator { x, y -> if (x.second == y.second) y.first - x.first else x.second - y.second }) 5 | .flatMap { xs -> 0.until(xs.second).map { xs.first } } 6 | .toIntArray() 7 | } 8 | -------------------------------------------------------------------------------- /Algorithms/1637_Widest_Vertical_Area_Between_Two_Points_Containing_No_Points/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun maxWidthOfVerticalArea(points: Array): Int = points.map { it.first() } 3 | .sorted() 4 | .zipWithNext { x, y -> y - x } 5 | .max()!! 6 | } 7 | -------------------------------------------------------------------------------- /Algorithms/1641_Count_Sorted_Vowel_Strings/solution.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int countVowelStrings(int n){ 4 | int vowels[6] = {1, 1, 1, 1, 1}; 5 | 6 | for (int i = 2; i <= n; ++i) { 7 | for (int j = 1; j < 5; ++j) { 8 | vowels[j] += vowels[j - 1]; 9 | } 10 | } 11 | 12 | int sum = 0; 13 | for (int i = 0; i < 5; ++i) { 14 | sum += vowels[i]; 15 | } 16 | 17 | return sum; 18 | } 19 | -------------------------------------------------------------------------------- /Algorithms/1646_Get_Maximum_in_Generated_Array/solution.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAX(a, b) (a < b ? b : a) 3 | 4 | int getMaximumGenerated(int n) { 5 | int max = n != 0; 6 | int arr[101] = {0, 1}; 7 | for (int i = 2; i <= n; ++i) { 8 | arr[i] = arr[i >> 1] + (i % 2 == 0 ? 0 : arr[(i >> 1) + 1]); 9 | max = MAX(max, arr[i]); 10 | } 11 | 12 | return max; 13 | } 14 | -------------------------------------------------------------------------------- /Algorithms/1657_Determine_if_Two_Strings_Are_Close/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def closeStrings(word1: String, word2: String): Boolean = word1.toSet == word2.toSet && 3 | word1.groupMapReduce(x => x)(_ => 1)(_ + _).values.toSet == word2.groupMapReduce(x => x)(_ => 1)(_ + _).values.toSet 4 | } 5 | 6 | -------------------------------------------------------------------------------- /Algorithms/1662_Check_If_Two_String_Arrays_are_Equivalent/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun arrayStringsAreEqual(word1: Array, word2: Array): Boolean = 3 | word1.joinToString("").equals(word2.joinToString("")) 4 | } -------------------------------------------------------------------------------- /Algorithms/1663_Smallest_String_With_A_Given_Numeric_Value/solution.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * getSmallestString(int n, int k) { 5 | char *seq = malloc(sizeof(char) * (n + 1)); 6 | for (int i = 0; i < n; seq[i++] = 'a'); 7 | seq[n] = '\0'; 8 | 9 | int diff = k - n; 10 | for (; diff >= 25; diff -= 25) { 11 | seq[--n] += 25; 12 | } 13 | if (n > 0) { 14 | seq[--n] += diff; 15 | } 16 | 17 | return seq; 18 | } 19 | -------------------------------------------------------------------------------- /Algorithms/1672_Richest_Customer_Wealth/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun maximumWealth(accounts: Array): Int = accounts.map { it.sum() }.max()!! 3 | } -------------------------------------------------------------------------------- /Algorithms/1678_Goal_Parser_Interpretation/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun interpret(command: String): String = 3 | command.replace("()", "o").replace("(al)", "al") 4 | } -------------------------------------------------------------------------------- /Algorithms/167_Two_Sum_II_-_Input_array_is_sorted/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} numbers 2 | # @param {Integer} target 3 | # @return {Integer[]} 4 | def two_sum(numbers, target) 5 | i, j = 0, numbers.length - 1 6 | while i < j 7 | k = numbers[i] + numbers[j] 8 | if k == target 9 | return i + 1, j + 1 10 | elsif k < target 11 | i += 1 12 | else 13 | j -= 1 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /Algorithms/1680_Concatenation_of_Consecutive_Binary_Numbers/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func concatenatedBinary(n int) int { 4 | inf, k, acc := 1000000007, 1, 0 5 | for i := n; i > 0; i-- { 6 | for j := i; j > 0; j >>= 1 { 7 | acc, k = (acc+(k*(j%2))%inf)%inf, (k<<1)%inf 8 | } 9 | } 10 | return acc 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/1684_Count_the_Number_of_Consistent_Strings/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def countConsistentStrings(allowed: String, words: Array[String]): Int = words.map(_.toSet.diff(allowed.toSet)).count(_.isEmpty) 3 | } 4 | -------------------------------------------------------------------------------- /Algorithms/1688_Count_of_Matches_in_Tournament/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {number} 4 | */ 5 | const numberOfMatches = n => n - 1; 6 | -------------------------------------------------------------------------------- /Algorithms/1689_Partitioning_Into_Minimum_Number_Of_Deci-Binary_Numbers/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun minPartitions(n: String): Int = n.max()!! - '0' 3 | } -------------------------------------------------------------------------------- /Algorithms/168_Excel_Sheet_Column_Title/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} n 2 | # @return {String} 3 | def convert_to_title(n) 4 | n < 27 ? (n + 64).chr : convert_to_title((n - 1) / 26) + convert_to_title(((n - 1) % 26) + 1) 5 | end 6 | -------------------------------------------------------------------------------- /Algorithms/169_Majority_Element/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun majorityElement(nums: IntArray): Int { 3 | val freq = HashMap() 4 | nums.forEach { it -> freq.merge(it, 1, Integer::sum) } 5 | val k = nums.size / 2 6 | for (f in freq) { 7 | if (f.value > k) { 8 | return f.key 9 | } 10 | } 11 | return 0 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Algorithms/1701_Average_Waiting_Time/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun averageWaitingTime(customers: Array): Double { 3 | var chefTime = 0 4 | var totalWaitingTime = .0 5 | for (c in customers) { 6 | if (chefTime < c[0]) { 7 | chefTime = c[0] 8 | } 9 | chefTime += c[1] 10 | totalWaitingTime += chefTime - c[0] 11 | } 12 | return totalWaitingTime / customers.size 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Algorithms/1710_Maximum_Units_on_a_Truck/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def maximumUnits(boxTypes: Array[Array[Int]], truckSize: Int): Int = { 3 | var (units, loaded) = 0 -> 0 4 | val sorted = boxTypes.sortWith((x, y) => x(1) > y(1)) 5 | for (box <- sorted) { 6 | if (loaded + box(0) >= truckSize) { 7 | units += (truckSize - loaded) * box(1) 8 | return units 9 | } 10 | loaded += box(0) 11 | units += box(0) * box(1) 12 | } 13 | boxTypes.map(xs => xs(0) * xs(1)).sum 14 | } 15 | } -------------------------------------------------------------------------------- /Algorithms/171_Excel_Sheet_Column_Number/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {String} s 2 | # @return {Integer} 3 | def title_to_number(s) 4 | len, num = s.length - 1, 0 5 | s.split('').each_with_index do |c, i| 6 | num += len > i ? (26 ** (len - i)) * (c.ord - 64) : c.ord - 64 7 | end 8 | num 9 | end 10 | -------------------------------------------------------------------------------- /Algorithms/1720_Decode_XORed_Array/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] decode(int[] encoded, int first) { 3 | int n = encoded.length; 4 | int[] ans = new int[n + 1]; 5 | ans[0] = first; 6 | for (int i = 0; i < n; ++i) { 7 | ans[i + 1] = ans[i] ^ encoded[i]; 8 | } 9 | return ans; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/1725_Number_Of_Rectangles_That_Can_Form_The_Largest_Square/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun countGoodRectangles(rectangles: Array) = rectangles 3 | .map { if (it[0] < it[1]) it[0] else it[1] } 4 | .let { minSides -> 5 | minSides.max()!!.let { maxSqrSide -> 6 | minSides.count { it >= maxSqrSide } 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Algorithms/172_Factorial_Trailing_Zeroes/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} n 2 | # @return {Integer} 3 | def trailing_zeroes(n) 4 | k, d = 0, 5 5 | k, d = k + (n / d), d * 5 while d <= n 6 | k 7 | end 8 | -------------------------------------------------------------------------------- /Algorithms/1732_Find_the_Highest_Altitude/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int largestAltitude(vector& gain) { 8 | int max_h = max(0, gain[0]); 9 | for (int i = 1; i < gain.size(); ++i) { 10 | gain[i] += gain[i - 1]; 11 | max_h = max(max_h, gain[i]); 12 | } 13 | return max_h; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /Algorithms/1742_Maximum_Number_of_Balls_in_a_Box/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun countBalls(lowLimit: Int, highLimit: Int) = lowLimit.rangeTo(highLimit) 3 | .map { it.toString() } 4 | .groupBy { it.map { it - '0' }.sum() } 5 | .map { it.value.size } 6 | .max()!! 7 | } 8 | -------------------------------------------------------------------------------- /Algorithms/1748_Sum_of_Unique_Elements/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun sumOfUnique(nums: IntArray) = nums.groupBy { it } 3 | .filter { it.value.size == 1 } 4 | .map { it.key } 5 | .sum() 6 | } 7 | -------------------------------------------------------------------------------- /Algorithms/1753_Maximum_Score_From_Removing_Stones/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun maximumScore(a: Int, b: Int, c: Int): Int { 3 | val scores = intArrayOf(a, b, c) 4 | var phase = 0 5 | while (true) { 6 | scores.sort() 7 | if (scores[0] == 0) { 8 | phase += kotlin.math.min(scores[1], scores[2]) 9 | break 10 | } 11 | ++phase 12 | --scores[0] 13 | --scores[2] 14 | } 15 | return phase 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Algorithms/1768_Merge_Strings_Alternately/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun mergeAlternately(word1: String, word2: String): String = word1.zip(word2).joinToString("") { "${it.first}${it.second}" } + 3 | if (word1.length < word2.length) word2.substring(word1.length) 4 | else word1.substring(word2.length) 5 | } 6 | -------------------------------------------------------------------------------- /Algorithms/1790_Check_if_One_String_Swap_Can_Make_Strings_Equal/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @github https://github.com/occidere 4 | * @blog https://blog.naver.com/occidere 5 | * @since 2022-07-07 6 | */ 7 | class Solution { 8 | fun areAlmostEqual(s1: String, s2: String) = 9 | s1 == s2 || (s1.toCharArray().sorted() == s2.toCharArray().sorted() && s1.indices.count { s1[it] != s2[it] } == 2) 10 | } 11 | -------------------------------------------------------------------------------- /Algorithms/1791_Find_Center_of_Star_Graph/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findCenter(int[][] edges) { 3 | return edges[0][0] == edges[1][0] || edges[0][0] == edges[1][1] ? edges[0][0] : edges[0][1]; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /Algorithms/179_Largest_Number/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun largestNumber(nums: IntArray): String = nums.map { it.toString() } 3 | .sortedWith(Comparator { a, b -> (b + a).compareTo(a + b) }) 4 | .joinToString("") 5 | .let { 6 | 0.until(it.length - 1) 7 | .takeWhile { i -> it[i] == '0' } 8 | .lastOrNull() 9 | ?.let { i -> it.substring(i + 1, it.length) } 10 | ?: it 11 | } 12 | } -------------------------------------------------------------------------------- /Algorithms/179_Largest_Number/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def largestNumber(nums: Array[Int]): String = nums.map(_.toString) 3 | .sortWith((a, b) => a + b > b + a) 4 | .mkString("") 5 | .dropWhile(_ == '0') match { 6 | case "" => "0" 7 | case s => s 8 | } 9 | } -------------------------------------------------------------------------------- /Algorithms/179_Largest_Number/solution.py: -------------------------------------------------------------------------------- 1 | from itertools import dropwhile 2 | from typing import * 3 | 4 | 5 | class Solution: 6 | def largestNumber(self, nums: List[int]) -> str: 7 | return ''.join(dropwhile(lambda c: c == '0', sorted(map(str, nums), key=self.SortFunc))) or '0' 8 | 9 | class SortFunc(str): 10 | def __lt__(x, y) -> bool: 11 | return x + y > y + x 12 | -------------------------------------------------------------------------------- /Algorithms/1807_Evaluate_the_Bracket_Pairs_of_a_String/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun evaluate(s: String, knowledge: List>) = knowledge.associate { it[0] to it[1] }.let { kv -> 3 | s.split(")").joinToString("") { 4 | if (!it.contains("(")) it else { 5 | it.split("(").run { 6 | first() + kv.getOrDefault(last(), "?") 7 | } 8 | } 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/1812_Determine_Color_of_a_Chessboard_Square/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool squareIsWhite(string coordinates) { 4 | int x = (coordinates[0] - 'a') % 2; 5 | int y = (coordinates[1] - '0') % 2; 6 | return (x == 0 && y == 0) || (x == 1 && y == 1); 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /Algorithms/1816_Truncate_Sentence/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun truncateSentence(s: String, k: Int): String = s.split(" ") 3 | .take(k) 4 | .joinToString(" ") 5 | } 6 | -------------------------------------------------------------------------------- /Algorithms/1822_Sign_of_the_Product_of_an_Array/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @github https://github.com/occidere 4 | * @blog https://blog.naver.com/occidere 5 | * @since 2022-07-07 6 | */ 7 | class Solution { 8 | fun arraySign(nums: IntArray) = nums.map { if (it < 0) -1 else if (it > 0) 1 else 0 } 9 | .groupBy { it } 10 | .mapValues { it.value.size } 11 | .let { if (it.contains(0)) 0 else if (it.getOrDefault(-1, 0) % 2 == 0) 1 else -1 } 12 | } 13 | -------------------------------------------------------------------------------- /Algorithms/1823_Find_the_Winner_of_the_Circular_Game/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @param {number} k 4 | * @return {number} 5 | */ 6 | const findTheWinner = function (n, k) { 7 | let friends = []; 8 | for (let i = 1; i <= n; ++i) { 9 | friends.push(i); 10 | } 11 | let pos = 0; 12 | while (friends.length > 1) { 13 | pos = (pos + k - 1) % friends.length; 14 | friends.splice(pos, 1); 15 | } 16 | return friends[0]; 17 | }; 18 | -------------------------------------------------------------------------------- /Algorithms/1827_Minimum_Operations_to_Make_the_Array_Increasing/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun minOperations(nums: IntArray) = nums.drop(1) 3 | .fold(nums.first() to 0) { acc, n -> 4 | with(if (acc.first < n) 0 else kotlin.math.abs(acc.first + 1 - n)) { 5 | if (this == 0) n to acc.second else Pair(acc.first + 1, acc.second + this) 6 | } 7 | }.second 8 | } 9 | -------------------------------------------------------------------------------- /Algorithms/1828_Queries_on_Number_of_Points_Inside_a_Circle/Solution.kt: -------------------------------------------------------------------------------- 1 | import kotlin.math.abs 2 | 3 | class Solution { 4 | fun countPoints(points: Array, queries: Array) = queries.map { q -> 5 | points.filter { p -> 6 | q[2] * q[2] >= 7 | abs(p[0] - q[0]).let { it * it } + 8 | abs(p[1] - q[1]).let { it * it } 9 | }.count() 10 | }.toIntArray() 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/1832_Check_if_the_Sentence_Is_Pangram/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun checkIfPangram(sentence: String) = sentence.toSet().size == 26 3 | } 4 | -------------------------------------------------------------------------------- /Algorithms/1833_Maximum_Ice_Cream_Bars/Solution.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Solution { 4 | public int maxIceCream(int[] costs, int coins) { 5 | Arrays.sort(costs); 6 | int count = 0; 7 | for (int c : costs) { 8 | if (coins < c) { 9 | break; 10 | } 11 | ++count; 12 | coins -= c; 13 | } 14 | return count; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Algorithms/1837_Sum_of_Digits_in_Base_K/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @param {number} k 4 | * @return {number} 5 | */ 6 | const sumBase = (n, k) => { 7 | let converted = ''; 8 | while (n > 0) { 9 | converted = (n % k) + converted; 10 | n = Math.floor(n / k); 11 | } 12 | return converted.split('') 13 | .map(x => Number.parseInt(x)) 14 | .reduce((a, b) => a + b, 0); 15 | }; 16 | -------------------------------------------------------------------------------- /Algorithms/1844_Replace_All_Digits_with_Characters/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String replaceDigits(String s) { 3 | char[] cs = s.toCharArray(); 4 | for (int i = 1; i < cs.length; i += 2) { 5 | cs[i] += cs[i - 1] - 48; 6 | } 7 | return new String(cs); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Algorithms/1859_Sorting_the_Sentence/Solution.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Solution { 4 | public String sortSentence(String s) { 5 | return Arrays.stream(s.split(" ")) 6 | .map(x -> new Object[]{x.charAt(x.length() - 1) - '0', x.substring(0, x.length() - 1)}) 7 | .sorted((a, b) -> Integer.compare((int) a[0], (int) b[0])) 8 | .map(x -> (String) x[1]) 9 | .collect(Collectors.joining(" ")); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/1863_Sum_of_All_Subset_XOR_Totals/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun subsetXORSum(nums: IntArray, idx: Int = 0, visit: Set = setOf()): Int { 3 | var acc = visit.map { nums[it] }.let { if (it.isEmpty()) 0 else it.reduce { x, y -> x.xor(y) } } 4 | for (i in idx.until(nums.size)) { 5 | if (!visit.contains(i)) { 6 | acc += subsetXORSum(nums, i, visit + i) 7 | } 8 | } 9 | return acc 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/1874_Minimize_Product_Sum_of_Two_Arrays/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun minProductSum(nums1: IntArray, nums2: IntArray): Int = nums1.sorted() 3 | .zip(nums2.sortedDescending()) 4 | .map { it.first * it.second } 5 | .sum() 6 | } 7 | -------------------------------------------------------------------------------- /Algorithms/1876_Substrings_of_Size_Three_with_Distinct_Characters/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-08-17 6 | */ 7 | class Solution { 8 | fun countGoodSubstrings(s: String): Int { 9 | var cnt = 0 10 | for (i in 0 until s.length - 2) { 11 | if (s[i] != s[i + 1] && s[i + 1] != s[i + 2] && s[i + 2] != s[i]) { 12 | ++cnt 13 | } 14 | } 15 | return cnt 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Algorithms/1877_Minimize_Maximum_Pair_Sum_in_Array/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun minPairSum(nums: IntArray): Int = nums.sorted() 3 | .zip(nums.sortedDescending()) 4 | .map { it.first + it.second } 5 | .take(nums.size shr 1) 6 | .max()!! 7 | } 8 | -------------------------------------------------------------------------------- /Algorithms/187_Repeated_DNA_Sequences/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun findRepeatedDnaSequences(s: String) = (10..(s.length)).asSequence() 3 | .map { s.substring(it - 10, it) } 4 | .groupBy { it } 5 | .map { it.key to it.value.size } 6 | .filter { it.second > 1 } 7 | .map { it.first } 8 | .toList() 9 | } 10 | -------------------------------------------------------------------------------- /Algorithms/1880_Check_if_Word_Equals_Summation_of_Two_Words/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isSumEqual(String firstWord, String secondWord, String targetWord) { 3 | return toInt(firstWord) + toInt(secondWord) == toInt(targetWord); 4 | } 5 | 6 | private int toInt(String s) { 7 | return Integer.parseInt(s.chars().mapToObj(c -> (c - 'a') + "").collect(Collectors.joining())); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Algorithms/1884_Egg_Drop_With_2_Eggs_and_N_Floors/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @github https://github.com/occidere 4 | * @blog https://blog.naver.com/occidere 5 | * @since 2022-11-03 6 | */ 7 | class Solution { 8 | fun twoEggDrop(n: Int): Int { 9 | var (f, d) = n to 0 10 | while (d + 1 < f) { 11 | f -= ++d 12 | } 13 | return d + 1 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Algorithms/1887_Reduction_Operations_to_Make_the_Array_Elements_Equal/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun reductionOperations(nums: IntArray): Int { 3 | val sorted = (listOf(Int.MAX_VALUE) + nums.sortedDescending()).toTypedArray() 4 | var ops = 0 5 | for (i in 1 until sorted.size) { 6 | if (sorted[i - 1] > sorted[i]) { 7 | ops += (i - 1) 8 | } 9 | } 10 | return ops 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Algorithms/189_Rotate_Array/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @param {Integer} k 3 | # @return {Void} Do not return anything, modify nums in-place instead. 4 | def rotate(nums, k) 5 | k %= nums.length 6 | nums.replace(nums[-k..-1] + (k > 0 ? nums[0..-1 - k] : [])) 7 | end 8 | -------------------------------------------------------------------------------- /Algorithms/190_Reverse_Bits/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} n, a positive integer 2 | # @return {Integer} 3 | def reverse_bits(n) 4 | n.to_s(2).rjust(32, '0').reverse.to_i(2) 5 | end 6 | -------------------------------------------------------------------------------- /Algorithms/1913_Maximum_Product_Difference_Between_Two_Pairs/Solution.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Solution { 4 | public int maxProductDifference(int[] nums) { 5 | Arrays.sort(nums); 6 | return nums[nums.length - 2] * nums[nums.length - 1] - nums[0] * nums[1]; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Algorithms/191_Number_of_1_Bits/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int hammingWeight(uint32_t n) { 8 | int a = 0; 9 | uint32_t i = n; 10 | for (; i > 2; a += i % 2, i >>= 1); 11 | return a + (i > 0); 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /Algorithms/191_Number_of_1_Bits/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} n, a positive integer 2 | # @return {Integer} 3 | def hamming_weight(n) 4 | n.to_s(2).split("").inject(0) {|sum, x| sum + x.to_i} 5 | end 6 | -------------------------------------------------------------------------------- /Algorithms/1920_Build_Array_from_Permutation/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun buildArray(nums: IntArray): IntArray = nums.indices.map { nums[nums[it]] }.toIntArray() 3 | } 4 | -------------------------------------------------------------------------------- /Algorithms/1929_Concatenation_of_Array/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun getConcatenation(nums: IntArray): IntArray = nums + nums 3 | } 4 | -------------------------------------------------------------------------------- /Algorithms/1935_Maximum_Number_of_Words_You_Can_Type/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun canBeTypedWords(text: String, brokenLetters: String) = brokenLetters.toSet().run { 3 | text.split(" ") 4 | .filter { it.none { c -> contains(c) } } 5 | .size 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Algorithms/1941_Check_if_All_Characters_Have_Equal_Number_of_Occurrences/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun areOccurrencesEqual(s: String) = s.groupBy { it }.map { it.value.size }.toSet().size == 1 3 | } 4 | -------------------------------------------------------------------------------- /Algorithms/1967_Number_of_Strings_That_Appear_as_Substrings_in_Word/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun numOfStrings(patterns: Array, word: String) = patterns.filter { word.contains(it) }.count() 3 | } 4 | -------------------------------------------------------------------------------- /Algorithms/1974_Minimum_Time_to_Type_Word_Using_Special_Typewriter/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} word 3 | * @return {number} 4 | */ 5 | const minTimeToType = word => { 6 | let p = 0; 7 | return word.split('') 8 | .map(w => { 9 | const c = w.charCodeAt(0) - 97; 10 | const sec = 1 + (p < c ? Math.min(c - p, 26 - c + p) : Math.min(p - c, 26 - p + c)); 11 | p = c; 12 | return sec; 13 | }).reduce((x, y) => x + y, 0); 14 | }; 15 | -------------------------------------------------------------------------------- /Algorithms/1979_Find_Greatest _Common_Divisor_of_Array/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | private fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b) 3 | fun findGCD(nums: IntArray) = gcd(nums.max()!!, nums.min()!!) 4 | } 5 | -------------------------------------------------------------------------------- /Algorithms/198_House_Robber/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Integer} 3 | def rob(nums) 4 | nums = [0, 0] + nums 5 | (2...nums.length).each { |i| nums[i] = [nums[i - 1], nums[i - 2] + nums[i]].max } 6 | nums[-1] 7 | end 8 | -------------------------------------------------------------------------------- /Algorithms/1991_Find_the_Middle_Index_in_Array/Solution.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | class Solution { 4 | public int findMiddleIndex(int[] nums) { 5 | int lefts = 0, rights = Arrays.stream(nums).sum() - nums[0], n = nums.length - 1; 6 | for (int i = 0; i < n; ++i) { 7 | if (lefts == rights) { 8 | return i; 9 | } 10 | lefts += nums[i]; 11 | rights -= nums[i + 1]; 12 | } 13 | return lefts == rights ? n : -1; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Algorithms/1_Two_Sum/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] twoSum(int[] nums, int target) { 3 | int len = nums.length; 4 | for (int i = 0; i < len; i++) { 5 | for (int j = i + 1; j < len; j++) { 6 | if (nums[i] + nums[j] == target) { 7 | return new int[]{i, j}; 8 | } 9 | } 10 | } 11 | 12 | return null; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Algorithms/2000_Reverse_Prefix_of_Word/Solution.kt: -------------------------------------------------------------------------------- 1 | import kotlin.math.max 2 | 3 | class Solution { 4 | fun reversePrefix(word: String, ch: Char) = max(word.indexOfFirst { it == ch }, 0) 5 | .let { "${word.substring(0..it).reversed()}${word.substring(it + 1 until word.length)}" } 6 | } 7 | -------------------------------------------------------------------------------- /Algorithms/2006_Count_Number_of_Pairs_With_Absolute_Difference_K/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @param {number} k 4 | * @return {number} 5 | */ 6 | const countKDifference = (nums, k) => { 7 | let count = 0; 8 | for (let i = 0; i < nums.length; ++i) { 9 | for (let j = i + 1; j < nums.length; ++j) { 10 | count += Math.abs(nums[i] - nums[j]) === k ? 1 : 0; 11 | } 12 | } 13 | return count; 14 | }; 15 | -------------------------------------------------------------------------------- /Algorithms/2011_Final_Value_of_Variable_After_Performing_Operations/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string[]} operations 3 | * @return {number} 4 | */ 5 | const finalValueAfterOperations = operations => { 6 | return operations.map(x => x.indexOf("++") > -1 ? 1 : -1).reduce((x, y) => x + y, 0); 7 | }; 8 | -------------------------------------------------------------------------------- /Algorithms/201_Bitwise_AND_of_Numbers_Range/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 참고: https://leetcode.com/problems/bitwise-and-of-numbers-range/discuss/593317/Simple-3-line-Java-solution-faster-than-100 3 | */ 4 | const rangeBitwiseAnd = (left, right) => { 5 | while (right > left) { 6 | right &= (right - 1); 7 | } 8 | return left & right; 9 | }; 10 | -------------------------------------------------------------------------------- /Algorithms/2023_Number_of_Pairs_of_Strings_With_Concatenation_Equal_to_Target/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun numOfPairs(nums: Array, target: String) = nums.indices 3 | .flatMap { i -> 4 | nums.indices.map { j -> 5 | if (i != j) nums[i] + nums[j] else "" 6 | } 7 | }.filter { it == target } 8 | .size 9 | } 10 | -------------------------------------------------------------------------------- /Algorithms/202_Happy_Number/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} n 2 | # @return {Boolean} 3 | def is_happy(n) 4 | visit = {} 5 | visit[n] = n = n.to_s.each_char.inject(0) { |sum, s| sum + (s.to_i ** 2) } while n != 1 and !visit[n] 6 | n == 1 7 | end 8 | -------------------------------------------------------------------------------- /Algorithms/2032_Two_Out_of_Three/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun twoOutOfThree(nums1: IntArray, nums2: IntArray, nums3: IntArray) = listOf(nums1, nums2, nums3) 3 | .flatMap { it.distinct() } 4 | .groupBy { it } 5 | .filter { it.value.size > 1 } 6 | .keys 7 | .toList() 8 | } 9 | -------------------------------------------------------------------------------- /Algorithms/2037_Minimum_Number_of_Moves_to_Seat_Everyone/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun minMovesToSeat(seats: IntArray, students: IntArray) = seats.sorted() 3 | .zip(students.sorted()) 4 | .map { kotlin.math.abs(it.first - it.second) } 5 | .sum() 6 | } 7 | -------------------------------------------------------------------------------- /Algorithms/2042_Check_if_Numbers_Are_Ascending_in_a_Sentence/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-09-17 6 | */ 7 | class Solution { 8 | fun areNumbersAscending(s: String) = s.split(" ") 9 | .mapNotNull { it.toIntOrNull() } 10 | .zipWithNext() 11 | .all { it.first < it.second } 12 | } 13 | -------------------------------------------------------------------------------- /Algorithms/2053_Kth_Distinct_String_in_an_Array/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun kthDistinct(arr: Array, k: Int) = arr.groupBy { it } 3 | .map { it.key to it.value.size } 4 | .filter { it.second == 1 } 5 | .let { if (it.size < k) "" else it[k - 1].first } 6 | } 7 | -------------------------------------------------------------------------------- /Algorithms/2057_Smallest_Index_With_Equal_Value/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun smallestEqual(nums: IntArray) = nums.withIndex().firstOrNull { it.index.rem(10) == it.value }?.index ?: -1 3 | } 4 | -------------------------------------------------------------------------------- /Algorithms/205_Isomorphic_Strings/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {String} s 2 | # @param {String} t 3 | # @return {Boolean} 4 | def is_isomorphic(s, t) 5 | a, b = [], [] 6 | (0...s.length).each do |i| 7 | sc, tc = s[i].ord, t[i].ord 8 | return false if a[sc] != b[tc] 9 | a[sc], b[tc] = i + 1, i + 1 10 | end 11 | true 12 | end -------------------------------------------------------------------------------- /Algorithms/2062_Count_Vowel_Substrings_of_a_String/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @github https://github.com/occidere 4 | * @blog https://blog.naver.com/occidere 5 | * @since 2022-11-02 6 | */ 7 | class Solution { 8 | fun countVowelSubstrings(word: String) = 9 | (5..word.length).flatMap { w -> 10 | (w..word.length).filter { 11 | "aeiou" == word.substring(it - w, it) 12 | .toSortedSet() 13 | .joinToString("") 14 | } 15 | }.count() 16 | } 17 | -------------------------------------------------------------------------------- /Algorithms/2063_Vowels_of_All_Substrings/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun countVowels(word: String): Long { 3 | var (numberOfVowels, a, b) = Triple(0L, 1L, word.length.toLong()) 4 | for (c in word) { 5 | if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') { 6 | numberOfVowels += a * b 7 | } 8 | ++a 9 | --b 10 | } 11 | return numberOfVowels 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Algorithms/2085_Count_Common_Words_With_One_Occurrence/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun countWords(words1: Array, words2: Array) = words1.groupBy { it } 3 | .filter { it.value.size == 1 } 4 | .keys 5 | .intersect(words2.groupBy { it }.filter { it.value.size == 1 }.keys) 6 | .size 7 | } 8 | -------------------------------------------------------------------------------- /Algorithms/2089_Find_Target_Indices_After_Sorting_Array/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun targetIndices(nums: IntArray, target: Int) = nums.sorted() 3 | .zip(nums.indices) 4 | .filter { it.first == target } 5 | .map { it.second } 6 | } 7 | -------------------------------------------------------------------------------- /Algorithms/2103_Rings_and_Rods/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun countPoints(rings: String) = (0.until(rings.length).step(2)) 3 | .groupBy({ i -> rings[i + 1] }, { i -> rings[i] }) 4 | .filter { it.value.toSet().size == 3 } 5 | .keys 6 | .size 7 | } 8 | -------------------------------------------------------------------------------- /Algorithms/2108_Find_First_Palindromic_String_in_the_Array/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun firstPalindrome(words: Array) = words.firstOrNull() { it.isPalindrome() } ?: "" 3 | 4 | private fun String.isPalindrome(): Boolean { 5 | val half = this.length.shr(1) 6 | for (i in 0..half) { 7 | if (this[i] != this[this.length - i - 1]) { 8 | return false 9 | } 10 | } 11 | return true 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Algorithms/2114_Maximum_Number_of_Words_Found_in_Sentences/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun mostWordsFound(sentences: Array) = sentences.map { it.split(" ") } 3 | .map { it.size } 4 | .max()!! 5 | } 6 | -------------------------------------------------------------------------------- /Algorithms/2119_A_Number_After_a_Double_Reversal/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun isSameAfterReversals(num: Int) = !(num != 0 && num.toString().endsWith("0")) 3 | } 4 | -------------------------------------------------------------------------------- /Algorithms/2124_Check_if_All_A's_Appears_Before_All_B's/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun checkString(s: String) = s.split("").sorted().joinToString("") == s 3 | } 4 | -------------------------------------------------------------------------------- /Algorithms/2125_Number_of_Laser_Beams_in_a_Bank/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun numberOfBeams(bank: Array) = bank.map { it.count { it == '1' } } 3 | .filter { it != 0 } 4 | .zipWithNext() 5 | .map { it.first * it.second } 6 | .sum() 7 | } 8 | -------------------------------------------------------------------------------- /Algorithms/2149_Rearrange_Array_Elements_by_Sign/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun rearrangeArray(nums: IntArray) = nums.filter { it > 0 } 3 | .zip(nums.filter { it < 0 }) 4 | .flatMap { listOf(it.first, it.second) } 5 | .toIntArray() 6 | } 7 | -------------------------------------------------------------------------------- /Algorithms/2150_Find_All_Lonely_Numbers_in_the_Array/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun findLonely(nums: IntArray) = nums.sorted().run { 3 | indices.map { 4 | val (prev, next) = Pair( 5 | if (it == 0) -2 else this[it - 1], 6 | if (it == size - 1) 1000002 else this[it + 1] 7 | ) 8 | if (this[it] in prev + 2 until next - 1) this[it] else -1 9 | }.filter { it >= 0 } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/2154_Keep_Multiplying_Found_Values_by_Two/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun findFinalValue(nums: IntArray, original: Int): Int { 3 | var k = original 4 | val sets = nums.toSet() 5 | while (sets.contains(k)) { 6 | k = k.shl(1) 7 | } 8 | return k 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Algorithms/215_Kth_Largest_Element_in_an_Array/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def findKthLargest(nums: Array[Int], k: Int): Int = 3 | nums.foldLeft(scala.collection.mutable.PriorityQueue[Int]())(_ += _).dequeueAll(k - 1) 4 | } -------------------------------------------------------------------------------- /Algorithms/2160_Minimum_Sum_of_Four_Digit_Number_After_Splitting_Digits/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun minimumSum(num: Int) = num.toString() 3 | .toCharArray() 4 | .sorted() 5 | .let { "${it[0]}${it[2]}".toInt() + "${it[1]}${it[3]}".toInt() } 6 | } 7 | -------------------------------------------------------------------------------- /Algorithms/2161_Partition_Array_According_to_Given_Pivot/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun pivotArray(nums: IntArray, pivot: Int) = 3 | (nums.filter { it < pivot } + nums.filter { it == pivot } + nums.filter { it > pivot }).toIntArray() 4 | } 5 | -------------------------------------------------------------------------------- /Algorithms/2169_Count_Operations_to_Obtain_Zero/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun countOperations(num1: Int, num2: Int): Int { 3 | var (a, b, cnt) = Triple(num1, num2, 0) 4 | while (a > 0 && b > 0) { 5 | if (a >= b) { 6 | a -= b 7 | } else { 8 | b -= a 9 | } 10 | ++cnt 11 | } 12 | return cnt 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Algorithms/2176_Count_Equal_and_Divisible_Pairs_in_an_Array/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun countPairs(nums: IntArray, k: Int): Int { 3 | var cnt = 0 4 | for (i in nums.indices) { 5 | for (j in i + 1 until nums.size) { 6 | if (nums[i] == nums[j] && i * j % k == 0) { 7 | ++cnt 8 | } 9 | } 10 | } 11 | return cnt 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Algorithms/2177_Find_Three_Consecutive_Integers_That_Sum_to_a_Given_Number/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun sumOfThree(num: Long) = 3 | if (num % 3L == 0L) longArrayOf(num / 3L - 1, num / 3L, num / 3L + 1) else longArrayOf() 4 | } 5 | -------------------------------------------------------------------------------- /Algorithms/217_Contains_Duplicate/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Boolean} 3 | def contains_duplicate(nums) 4 | nums.sort! 5 | (0..nums.length - 2).each { |i| return true if nums[i] == nums[i + 1] } 6 | false 7 | end -------------------------------------------------------------------------------- /Algorithms/2180_Count_Integers_With_Even_Digit_Sum/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-10-01 6 | */ 7 | class Solution { 8 | fun countEven(num: Int) = (1..num).count { n -> "$n".sumBy { it - '0' } % 2 == 0 } 9 | } 10 | -------------------------------------------------------------------------------- /Algorithms/2185_Counting_Words_With_a_Given_Prefix/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun prefixCount(words: Array, pref: String) = words.count { it.startsWith(pref) } 3 | } 4 | -------------------------------------------------------------------------------- /Algorithms/2194_Cells_in_a_Range_on_an_Excel_Sheet/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun cellsInRange(s: String) = (s[0]..s[3]).flatMap { r -> (s[1]..s[4]).map { c -> "$r${c - '0'}" } } 3 | } 4 | -------------------------------------------------------------------------------- /Algorithms/2206_Divide_Array_Into_Equal_Pairs/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun divideArray(nums: IntArray): Boolean { 3 | nums.sort() 4 | for (i in 0.until(nums.size).step(2)) { 5 | if (nums[i] != nums[i + 1]) { 6 | return false 7 | } 8 | } 9 | return true 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/2215_Find_the_Difference_of_Two_Arrays/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-08-21 6 | */ 7 | class Solution { 8 | fun findDifference(nums1: IntArray, nums2: IntArray) = Pair(nums1.toSet(), nums2.toSet()) 9 | .let { (xs, ys) -> listOf(xs.subtract(ys).toList(), ys.subtract(xs).toList()) } 10 | } 11 | -------------------------------------------------------------------------------- /Algorithms/2220_Minimum_Bit_Flips_to_Convert/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @github https://github.com/occidere 4 | * @blog https://blog.naver.com/occidere 5 | * @since 2022-09-21 6 | */ 7 | class Solution { 8 | fun minBitFlips(start: Int, goal: Int) = Integer.toBinaryString(start.xor(goal)) 9 | .map { it - '0' } 10 | .sum() 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/2221_Find_Triangular_Sum_of_an_Array/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun triangularSum(nums: IntArray) = nums.apply { 3 | repeat(size - 1) { 4 | 1.until(size - it).forEach { i -> this[i - 1] = (this[i - 1] + this[i]) % 10 } 5 | } 6 | }.first() 7 | } 8 | -------------------------------------------------------------------------------- /Algorithms/2225_Find_Players_With_Zero_or_One_Losses/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun findWinners(matches: Array) = matches.run { 3 | map { it.last() } 4 | .let { losers -> 5 | listOf( 6 | flatMap { it.toList() }.toSet().subtract(losers.toSet()).toList().sorted(), 7 | losers.groupBy { it }.filter { it.value.size == 1 }.keys.toList().sorted() 8 | ) 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/2235_Add_Two_Integers/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun sum(num1: Int, num2: Int) = num1 + num2 3 | } 4 | -------------------------------------------------------------------------------- /Algorithms/2236_Root_Equals_Sum_of_Children/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * Example: 3 | * var ti = TreeNode(5) 4 | * var v = ti.`val` 5 | * Definition for a binary tree node. 6 | * class TreeNode(var `val`: Int) { 7 | * var left: TreeNode? = null 8 | * var right: TreeNode? = null 9 | * } 10 | */ 11 | class Solution { 12 | fun checkTree(root: TreeNode) = root.`val` == root.left!!.`val` + root.right!!.`val` 13 | } 14 | -------------------------------------------------------------------------------- /Algorithms/2248_Intersection_of_Multiple_Arrays/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @github https://github.com/occidere 4 | * @blog https://blog.naver.com/occidere 5 | * @since 2022-08-18 6 | */ 7 | class Solution { 8 | fun intersection(nums: Array) = nums.map { it.toSet() } 9 | .reduce { acc, ints -> acc.intersect(ints) } 10 | .sorted() 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/2255_Count_Prefixes_of_a_Given_String/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-08-16 6 | */ 7 | class Solution { 8 | fun countPrefixes(words: Array, s: String) = words.count { s.startsWith(it) } 9 | } 10 | -------------------------------------------------------------------------------- /Algorithms/226_Invert_Binary_Tree/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | /** 4 | * Definition for a binary tree node. 5 | * type TreeNode struct { 6 | * Val int 7 | * Left *TreeNode 8 | * Right *TreeNode 9 | * } 10 | */ 11 | func invertTree(root *TreeNode) *TreeNode { 12 | if root != nil { 13 | invertTree(root.Left) 14 | invertTree(root.Right) 15 | root.Left, root.Right = root.Right, root.Left 16 | } 17 | return root 18 | } -------------------------------------------------------------------------------- /Algorithms/226_Invert_Binary_Tree/solution.py: -------------------------------------------------------------------------------- 1 | # Definition for a binary tree node. 2 | # class TreeNode: 3 | # def __init__(self, x): 4 | # self.val = x 5 | # self.left = None 6 | # self.right = None 7 | class Solution: 8 | def invertTree(self, root: TreeNode) -> TreeNode: 9 | if root is None: 10 | return root 11 | self.invertTree(root.left) 12 | self.invertTree(root.right) 13 | root.left, root.right = root.right, root.left 14 | return root 15 | -------------------------------------------------------------------------------- /Algorithms/2278_Percentage_of_Letter_in_String/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun percentageLetter(s: String, letter: Char) = 100 * s.groupBy { it } 3 | .mapValues { it.value.size } 4 | .getOrDefault(letter, 0) / s.length 5 | } 6 | -------------------------------------------------------------------------------- /Algorithms/2279_Maximum_Bags_With_Full_Capacity_of_Rocks/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun maximumBags(capacity: IntArray, rocks: IntArray, additionalRocks: Int): Int { 3 | var remains = additionalRocks 4 | return capacity.zip(rocks) 5 | .map { it.first - it.second } 6 | .sorted() 7 | .map { 8 | if (it in 1..remains) { 9 | remains -= it 10 | 0 11 | } else it 12 | }.count { it == 0 } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Algorithms/2283_Check_if_Number_Has_Equal_Digit_Count_and_Digit_Value/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun digitCount(num: String): Boolean { 3 | val group = num.map { it - '0' } 4 | .groupBy { it } 5 | .mapValues { it.value.size } 6 | for (i in num.indices) { 7 | if (group.getOrDefault(i, 0) != num[i] - '0') { 8 | return false 9 | } 10 | } 11 | return true 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Algorithms/2295_Replace_Elements_in_an_Array/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun arrayChange(nums: IntArray, operations: Array): IntArray { 3 | val posMap = nums.indices.associateBy { nums[it] }.toMutableMap() 4 | for ((x, y) in operations) { 5 | val pos = posMap[x]!! 6 | posMap.remove(x) 7 | posMap[y] = pos 8 | } 9 | return nums.apply { posMap.forEach { (k, v) -> this[v] = k } } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/2315_Count_Asterisks/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun countAsterisks(s: String) = s.split('|') 3 | .toTypedArray() 4 | .run { 5 | indices.filter { it % 2 == 0 } 6 | .map { this[it].count { c -> c == '*' } } 7 | .sum() 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Algorithms/231_Power_of_Two/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func isPowerOfTwo(n int) bool { 4 | return n != 0 && (n & (n - 1) == 0) 5 | } -------------------------------------------------------------------------------- /Algorithms/2325_Decode_the_Message/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun decodeMessage(key: String, message: String) = key.filter { it != ' ' } 3 | .toList() 4 | .distinct() 5 | .let { it.zip(it.indices.map { i -> (i + 97).toChar() }) } 6 | .toMap() 7 | .run { 8 | message.map { getOrDefault(it, it) } 9 | .joinToString("") 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/2341_Maximum_Number_of_Pairs_in_Array/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-08-11 6 | */ 7 | class Solution { 8 | fun numberOfPairs(nums: IntArray) = nums.groupBy { it } 9 | .values 10 | .map { intArrayOf(it.size.shr(1), it.size % 2) } 11 | .reduce { acc, pair -> intArrayOf(acc[0] + pair[0], acc[1] + pair[1]) } 12 | } 13 | -------------------------------------------------------------------------------- /Algorithms/2351_First_Letter_to_Appear_Twice/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-08-15 6 | */ 7 | class Solution { 8 | fun repeatedCharacter(s: String) = 9 | IntArray(26) { 0 }.let { visit -> 10 | s.forEach { 11 | if (++visit[it - 'a'] == 2) { 12 | return it 13 | } 14 | } 15 | ' ' 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Algorithms/2363_Merge_Similar_Items/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-08-12 6 | */ 7 | class Solution { 8 | fun mergeSimilarItems(items1: Array, items2: Array) = 9 | (items1 + items2).groupBy({ it[0] }, { it[1] }) 10 | .map { listOf(it.key, it.value.sum()) } 11 | .sortedBy { it.first() } 12 | } 13 | -------------------------------------------------------------------------------- /Algorithms/237_Delete_Node_in_a_Linked_List/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | /** 4 | * Definition for singly-linked list. 5 | * type ListNode struct { 6 | * Val int 7 | * Next *ListNode 8 | * } 9 | */ 10 | func deleteNode(node *ListNode) { 11 | *node = *node.Next 12 | } -------------------------------------------------------------------------------- /Algorithms/2389_Longest_Subsequence_With_Limited_Sum/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-12-25 6 | */ 7 | class Solution { 8 | fun answerQueries(nums: IntArray, queries: IntArray) = 9 | queries.also { nums.sort() } 10 | .map { q -> 11 | var acc = 0 12 | nums.takeWhile { (acc + it <= q).apply { acc += it } }.size 13 | }.toIntArray() 14 | } 15 | -------------------------------------------------------------------------------- /Algorithms/238_Product_of_Array_Except_Self/solution.py: -------------------------------------------------------------------------------- 1 | from typing import * 2 | 3 | 4 | class Solution: 5 | def productExceptSelf(self, nums: List[int]) -> List[int]: 6 | right, res = 1, [1 for _ in range(len(nums))] 7 | for i in range(1, len(nums)): 8 | res[i] *= nums[i - 1] * res[i - 1] 9 | for i in range(len(nums) - 2, -1, -1): 10 | res[i] *= nums[i + 1] * right 11 | right *= nums[i + 1] 12 | return res 13 | -------------------------------------------------------------------------------- /Algorithms/2396_Strictly_Palindromic_Number/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-09-07 6 | */ 7 | class Solution { 8 | fun isStrictlyPalindromic(n: Int) = false 9 | } 10 | -------------------------------------------------------------------------------- /Algorithms/2399_Check_Distances_Between_Same_Letters/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @github https://github.com/occidere 4 | * @blog https://blog.naver.com/occidere 5 | * @since 2022-09-11 6 | */ 7 | class Solution { 8 | fun checkDistances(s: String, distance: IntArray) = s.indices 9 | .map { s[it] to it } 10 | .groupBy({ it.first }) { it.second } 11 | .all { (c, xs) -> xs.zipWithNext().all { (i, j) -> j - i - 1 == distance[c - 'a'] } } 12 | } 13 | -------------------------------------------------------------------------------- /Algorithms/240_Search_a_2D_Matrix_II/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func searchMatrix(matrix [][]int, target int) bool { 4 | row, col := len(matrix)-1, 0 5 | for ; 0 <= row && col < len(matrix[0]); { 6 | cur := matrix[row][col] 7 | if cur < target { 8 | col++ 9 | } else if cur > target { 10 | row-- 11 | } else { 12 | return true 13 | } 14 | } 15 | 16 | return false 17 | } 18 | -------------------------------------------------------------------------------- /Algorithms/2418_Sort_the_People/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @github https://github.com/occidere 4 | * @blog https://blog.naver.com/occidere 5 | * @since 2022-09-28 6 | */ 7 | class Solution { 8 | fun sortPeople(names: Array, heights: IntArray) = names.indices 9 | .map { names[it] to heights[it] } 10 | .sortedByDescending { it.second } 11 | .map { it.first } 12 | .toTypedArray() 13 | } 14 | -------------------------------------------------------------------------------- /Algorithms/2427_Number_of_Common_Factors/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun commonFactors(a: Int, b: Int) = 3 | (1..kotlin.math.min(a, b)).count { a % it == 0 && b % it == 0 } 4 | } 5 | -------------------------------------------------------------------------------- /Algorithms/242_Valid_Anagram/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def isAnagram(s: String, t: String): Boolean = s.map(_ -> 1).groupMapReduce(_._1)(_._2)(_ + _) == 3 | t.map(_ -> 1).groupMapReduce(_._1)(_._2)(_ + _) 4 | 5 | def main(args: Array[String]): Unit = { 6 | println(isAnagram("anagram", "nagaram")) 7 | } 8 | } -------------------------------------------------------------------------------- /Algorithms/2433_Find_The_Original_Array_of_Prefix_Xor/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-10-12 6 | */ 7 | class Solution { 8 | fun findArray(pref: IntArray) = (listOf(0) + pref.toList()) 9 | .zipWithNext() 10 | .map { it.first.xor(it.second) } 11 | .toIntArray() 12 | } 13 | -------------------------------------------------------------------------------- /Algorithms/2441_Largest_Positive_Integer_That_Exists_With_Its_Negative/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @github https://github.com/occidere 4 | * @blog https://blog.naver.com/occidere 5 | * @since 2022-10-17 6 | */ 7 | class Solution { 8 | fun findMaxK(nums: IntArray) = nums.toSet() 9 | .let { sets -> sets.filter { sets.contains(-it) }.max() ?: -1 } 10 | } 11 | -------------------------------------------------------------------------------- /Algorithms/2442_Count_Number_of_Distinct_Integers_After_Reverse_Operations/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-10-16 6 | */ 7 | class Solution { 8 | fun countDistinctIntegers(nums: IntArray) = nums.joinToString(",") 9 | .run { "$this,${reversed()}" } 10 | .split(",") 11 | .map { it.toInt() } 12 | .toSet() 13 | .size 14 | } 15 | -------------------------------------------------------------------------------- /Algorithms/2469_Convert_the_Temperature/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-11-13 6 | */ 7 | class Solution { 8 | fun convertTemperature(celsius: Double) = doubleArrayOf(celsius + 273.15, celsius * 1.8 + 32) 9 | } 10 | -------------------------------------------------------------------------------- /Algorithms/2490_Circular_Sentence/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-12-27 6 | */ 7 | class Solution { 8 | fun isCircularSentence(sentence: String) = 9 | sentence.split(" ") 10 | .let { xs -> xs.indices.all { i -> xs[i].last() == xs[(i + 1) % xs.size].first() } } 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/2496_Maximum_Value_of_a_String_in_an_Array/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @github https://github.com/occidere 4 | * @blog https://blog.naver.com/occidere 5 | * @since 2022-12-16 6 | */ 7 | class Solution { 8 | fun maximumValue(strs: Array) = strs.map { it.toIntOrNull() ?: it.length }.max()!! 9 | } 10 | -------------------------------------------------------------------------------- /Algorithms/2506_Count_Pairs_Of_Similar_Strings/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-12-26 6 | */ 7 | class Solution { 8 | fun similarPairs(words: Array) = 9 | words.map { it.asSequence().toSortedSet().joinToString("") } 10 | .let { ws -> ws.indices.sumBy { i -> (i + 1 until ws.size).count { j -> ws[i] == ws[j] } } } 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/252_Meeting_Rooms/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun canAttendMeetings(intervals: Array): Boolean = if (intervals.size < 2) true else 3 | !intervals.sortedWith(Comparator { a, b -> if (a[0] == b[0]) a[1] - b[1] else a[0] - b[0] }) 4 | .zipWithNext() 5 | .map { it.first[1] > it.second[0] } 6 | .reduce { acc, e -> acc || e } 7 | } -------------------------------------------------------------------------------- /Algorithms/258_Add_Digits/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun addDigits(num: Int) = if (num < 10) num else if (num % 9 == 0) 9 else num % 9 3 | } 4 | -------------------------------------------------------------------------------- /Algorithms/266_Palindrome_Permutation/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun canPermutePalindrome(s: String): Boolean = mutableSetOf().apply { 3 | for (c in s) { 4 | if (c in this) this.remove(c) else this += c 5 | } 6 | }.size < 2 7 | } -------------------------------------------------------------------------------- /Algorithms/268_Missing_Number/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func missingNumber(nums []int) int { 4 | sum, acc := 0, 0 5 | for i, n := range nums { 6 | sum, acc = sum+i+1, acc+n 7 | } 8 | return sum - acc 9 | } 10 | -------------------------------------------------------------------------------- /Algorithms/26_Remove_Duplicates_from_Sorted_Array/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun removeDuplicates(nums: IntArray): Int { 3 | return if (nums.isEmpty()) { 4 | 0 5 | } else { 6 | var cnt = 1 7 | for (i in 1 until nums.size) { 8 | if (nums[i] != nums[i - 1]) { 9 | nums[cnt] = nums[i] 10 | cnt++ 11 | } 12 | } 13 | cnt 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Algorithms/274_H-Index/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "sort" 4 | 5 | func hIndex(citations []int) int { 6 | sort.Ints(citations) 7 | n := len(citations) 8 | for h := 0; h < n; h++ { 9 | if citations[h] >= n-h { 10 | return n - h 11 | } 12 | } 13 | return 0 14 | } -------------------------------------------------------------------------------- /Algorithms/27_Remove_Element/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun removeElement(nums: IntArray, `val`: Int): Int { 3 | var idx = 0 4 | for (i in 0 until nums.size) { 5 | if (nums[i] != `val`) { 6 | nums[idx++] = nums[i] 7 | } 8 | } 9 | return idx 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/283_Move_Zeroes/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Void} Do not return anything, modify nums in-place instead. 3 | def move_zeroes(nums) 4 | (l = 0...nums.length).each do |r| 5 | if nums[l] == 0 and nums[r] != 0 6 | nums[l], nums[r] = nums[r], nums[l] 7 | l += 1 8 | elsif nums[l] != 0 and nums[r] == 0 9 | l = r 10 | end 11 | end 12 | end -------------------------------------------------------------------------------- /Algorithms/287_Find_the_Duplicate_Number/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def findDuplicate(nums: Array[Int]): Int = { 3 | var slow = nums(0) 4 | var fast = nums(slow) 5 | 6 | while (slow != fast) { 7 | slow = nums(slow) 8 | fast = nums(nums(fast)) 9 | } 10 | 11 | fast = 0 12 | while (slow != fast) { 13 | slow = nums(slow) 14 | fast = nums(fast) 15 | } 16 | slow 17 | } 18 | } -------------------------------------------------------------------------------- /Algorithms/300_Longest_Increasing_Subsequence/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def lengthOfLIS(nums: Array[Int]): Int = if (nums.isEmpty) 0 else { 3 | val d = Array.fill(nums.length)(1) 4 | for (i <- Range(1, d.length); j <- Range(0, i + 1)) 5 | if (nums(i) > nums(j) && d(i) < d(j) + 1) d(i) = d(j) + 1 6 | d.max 7 | } 8 | } -------------------------------------------------------------------------------- /Algorithms/322_Coin_Change/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def coinChange(coins: Array[Int], amount: Int): Int = { 3 | val d = Array.fill(amount + 1)(0x3f3f3f3f) 4 | d(0) = 0 5 | 6 | for (coin <- coins; i <- Range(coin, amount + 1)) d(i) = d(i) min d(i - coin) + 1 7 | 8 | if (d(amount) < 0x3f3f3f3f) d(amount) else -1 9 | } 10 | } -------------------------------------------------------------------------------- /Algorithms/326_Power_of_Three/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isPowerOfThree(int n) { 3 | return n > 0 && (n == 1 || (n % 3 == 0 && isPowerOfThree(n / 3))); 4 | } 5 | } -------------------------------------------------------------------------------- /Algorithms/326_Power_of_Three/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} n 2 | # @return {Boolean} 3 | def is_power_of_three(n) 4 | n > 0 and (n == 1 or (n % 3 == 0 and is_power_of_three(n / 3))) 5 | end -------------------------------------------------------------------------------- /Algorithms/342_Power_of_Four/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun isPowerOfFour(n: Int): Boolean { 3 | if (n < 0) { 4 | return false 5 | } else if (n == 1) { 6 | return true 7 | } 8 | 9 | var k = 4L 10 | while (true) { 11 | if (k == n.toLong()) { 12 | return true 13 | } else if (k > n.toLong()) { 14 | return false 15 | } 16 | k = k.shl(2) 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Algorithms/343_Integer_Break/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun integerBreak(n: Int) = when (n) { 3 | 2 -> 1 4 | 3 -> 2 5 | else -> { 6 | var (num, prd) = Pair(n, 1) 7 | while (num > 4) { 8 | prd *= 3 9 | num -= 3 10 | } 11 | prd * num 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Algorithms/344_Reverse_String/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | void reverseString(vector& s) { 8 | int len = s.size(); 9 | int half = len / 2; 10 | for (int i = 0; i < half; i++) { 11 | char ch = s[i]; 12 | s[i] = s[len - i - 1]; 13 | s[len - i - 1] = ch; 14 | } 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /Algorithms/344_Reverse_String/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func reverseString(s []byte) { 6 | for i := 0; i < len(s)>>1; i++ { 7 | s[i], s[len(s)-i-1] = s[len(s)-i-1], s[i] 8 | } 9 | } 10 | 11 | func main() { 12 | s := []byte{'a', 'b', 'c', 'd', 'e'} 13 | reverseString(s) 14 | fmt.Println(s) 15 | } 16 | -------------------------------------------------------------------------------- /Algorithms/346_Moving_Average_from_Data_Stream/Solution.kt: -------------------------------------------------------------------------------- 1 | class MovingAverage(private val size: Int) { 2 | private val data = arrayListOf() 3 | 4 | fun next(`val`: Int): Double { 5 | data += `val` 6 | if (data.size > size) { 7 | data.removeAt(0) 8 | } 9 | return data.average() 10 | } 11 | } -------------------------------------------------------------------------------- /Algorithms/347_Top_K_Frequent_Elements/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def topKFrequent(nums: Array[Int], k: Int): Array[Int] = nums.groupMapReduce(n => n)(_ => 1)(_ + _) 3 | .foldLeft(scala.collection.mutable.PriorityQueue[(Int, Int)]()(Ordering.by(_._2)))(_ += _) 4 | .dequeueAll 5 | .take(k) 6 | .map(_._1) 7 | .toArray 8 | } -------------------------------------------------------------------------------- /Algorithms/349_Intersection_of_Two_Arrays/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums1 2 | # @param {Integer[]} nums2 3 | # @return {Integer[]} 4 | def intersection(nums1, nums2) 5 | (nums1 & nums2).uniq 6 | end 7 | -------------------------------------------------------------------------------- /Algorithms/35_Search_Insert_Position/Solution.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | 4 | class Solution: 5 | def searchInsert(self, nums: List[int], target: int) -> int: 6 | return len([x for x in nums if x < target]) 7 | -------------------------------------------------------------------------------- /Algorithms/35_Search_Insert_Position/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func searchInsert(nums []int, target int) int { 4 | i := 0 5 | for ; i < len(nums) && nums[i] < target; i++ {} 6 | return i 7 | } -------------------------------------------------------------------------------- /Algorithms/378_Kth_Smallest_Element_in_a_Sorted_Matrix/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def kthSmallest(matrix: Array[Array[Int]], k: Int): Int = { 3 | val pq = matrix.flatten.foldLeft(scala.collection.mutable.PriorityQueue[Int]())(_ += -_) 4 | Iterator.range(0, k) 5 | .map(_ => -pq.dequeue()) 6 | .toList 7 | .last 8 | } 9 | } -------------------------------------------------------------------------------- /Algorithms/383_Ransom_Note/solution.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | 3 | 4 | class Solution: 5 | def canConstruct(self, ransomNote: str, magazine: str) -> bool: 6 | buf = defaultdict(lambda: 0) 7 | 8 | for s in magazine: 9 | buf[s] += 1 10 | 11 | for s in ransomNote: 12 | if buf[s] < 1: 13 | return False 14 | else: 15 | buf[s] -= 1 16 | 17 | return True; 18 | -------------------------------------------------------------------------------- /Algorithms/387_First_Unique_Character_in_a_String/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int firstUniqChar(string s) { 8 | int freq[26] = {0}; 9 | for (int i = 0; i < s.length(); ++freq[s[i++] - 'a']); 10 | for (int i = 0; i < s.length(); ++i) { 11 | if (freq[s[i] - 'a'] == 1) { 12 | return i; 13 | } 14 | } 15 | return -1; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /Algorithms/389_Find_the_Difference/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func findTheDifference(s string, t string) byte { 4 | freq := [26]int{0} 5 | 6 | for _, v := range s { 7 | freq[v - 'a'] += 1 8 | } 9 | for _, v := range t { 10 | freq[v - 'a'] -= 1 11 | } 12 | 13 | for k, v := range freq { 14 | if v != 0 { 15 | return byte(k + 'a') 16 | } 17 | } 18 | return 0 19 | } 20 | -------------------------------------------------------------------------------- /Algorithms/412_Fizz_Buzz/Solution.scala: -------------------------------------------------------------------------------- 1 | object Utils { 2 | implicit class DivUtils(x: Int) { 3 | def toFizzBuzzNum: String = if (x % 15 == 0) "FizzBuzz" else if (x % 3 == 0) "Fizz" else if (x % 5 == 0) "Buzz" else x.toString 4 | } 5 | } 6 | 7 | object Solution { 8 | import Utils._ 9 | def fizzBuzz(n: Int): List[String] = Iterator.range(1, n + 1).map(_.toFizzBuzzNum).toList 10 | } -------------------------------------------------------------------------------- /Algorithms/413_Arithmetic_Slices/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func numberOfArithmeticSlices(A []int) int { 4 | acc, cur := 0, 0 5 | 6 | for i := 2; i < len(A); i++ { 7 | if A[i-1]-A[i-2] == A[i]-A[i-1] { 8 | cur++ 9 | acc += cur 10 | } else { 11 | cur = 0 12 | } 13 | } 14 | 15 | return acc 16 | } 17 | -------------------------------------------------------------------------------- /Algorithms/414_Third_Maximum_Number/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @github https://github.com/occidere 4 | * @blog https://blog.naver.com/occidere 5 | * @since 2022-12-08 6 | */ 7 | class Solution { 8 | fun thirdMax(nums: IntArray) = nums.asSequence() 9 | .distinct() 10 | .sortedDescending() 11 | .take(3) 12 | .toList() 13 | .let { if (it.size < 3) it.first() else it.last() } 14 | } 15 | -------------------------------------------------------------------------------- /Algorithms/419_Battleships_in_a_Board/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Character[][]} board 2 | # @return {Integer} 3 | def count_battleships(board) 4 | cnt = 0 5 | (0...board.length).each do |i| 6 | (0...board[0].length).each do |j| 7 | cnt += 1 if is_first_part?(board, i, j) 8 | end 9 | end 10 | cnt 11 | end 12 | 13 | def is_first_part?(board, i, j) 14 | left, up = j > 0 ? board[i][j - 1] : '.', i > 0 ? board[i - 1][j] : '.' 15 | board[i][j] == 'X' and left == '.' and up == '.' 16 | end -------------------------------------------------------------------------------- /Algorithms/41_First_Missing_positive/Solution.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | 4 | class Solution: 5 | def firstMissingPositive(self, nums: List[int]) -> int: 6 | nums = sorted(set(filter(lambda _: _ > 0, nums))) 7 | i = 1 8 | for n in nums: 9 | if i != n: 10 | break 11 | i += 1 12 | return i 13 | -------------------------------------------------------------------------------- /Algorithms/434_Number_of_Segments_in_a_String/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-12-11 6 | */ 7 | class Solution { 8 | fun countSegments(s: String) = s.split(' ').filter { it.length != 0 }.size 9 | } 10 | -------------------------------------------------------------------------------- /Algorithms/441_Arranging_Coins/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun arrangeCoins(n: Int): Int { 3 | var (a, b) = 1L to 2L 4 | var k = 2L 5 | while (true) { 6 | if (n in a..b) { 7 | return (k - 1).toInt() 8 | } 9 | a += k++ 10 | b += k 11 | } 12 | return 0 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Algorithms/442_Find_All_Duplicates_in_an_Array/Solution.scala: -------------------------------------------------------------------------------- 1 | import scala.collection.mutable.ListBuffer 2 | 3 | object Solution { 4 | def findDuplicates(nums: Array[Int]): List[Int] = { 5 | val dup = new ListBuffer[Int]() 6 | 7 | for (i <- nums.indices) { 8 | val idx = Math.abs(nums(i)) 9 | if (nums(idx - 1) > 0) nums(idx - 1) *= -1 10 | else dup += Math.abs(nums(i)) 11 | } 12 | 13 | dup.result() 14 | } 15 | } -------------------------------------------------------------------------------- /Algorithms/442_Find_All_Duplicates_in_an_Array/Solution2.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def findDuplicates(nums: Array[Int]): List[Int] = nums.indices.map(x => { 3 | val idx = Math.abs(nums(x)) - 1 4 | if (nums(idx) <= 0) idx + 1 else { 5 | nums(idx) *= -1 6 | 0 7 | } 8 | }).foldLeft(List.empty[Int])((xs, x) => if (x != 0) xs :+ x else xs) 9 | } -------------------------------------------------------------------------------- /Algorithms/443_String_Compression/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "strconv" 4 | 5 | func compress(chars []byte) int { 6 | k, n := 0, len(chars) 7 | for i := 0; i < n; { 8 | cnt, j := 1, i+1 9 | for ; j < n && chars[i] == chars[j]; j++ { 10 | cnt++ 11 | } 12 | 13 | chars[k], k = chars[i], k+1 14 | if cnt > 1 { 15 | for _, c := range strconv.Itoa(cnt) { 16 | chars[k], k = byte(c), k+1 17 | } 18 | } 19 | i = j 20 | } 21 | 22 | return k 23 | } -------------------------------------------------------------------------------- /Algorithms/448_Find_All_Numbers_Disappeared_in_an_Array/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun findDisappearedNumbers(nums: IntArray) = (1..nums.size).toSet() 3 | .subtract(nums.toSet()) 4 | .toList() 5 | } 6 | -------------------------------------------------------------------------------- /Algorithms/458_Poor_Pigs/Solution.kt: -------------------------------------------------------------------------------- 1 | import kotlin.math.ceil 2 | import kotlin.math.ln 3 | 4 | /** 5 | * Ref: https://me2.do/FuW36ryf 6 | * 7 | * @author occidere 8 | * @Blog: https://blog.naver.com/occidere 9 | * @Github: https://github.com/occidere 10 | * @since 2022-08-06 11 | */ 12 | class Solution { 13 | fun poorPigs(buckets: Int, minutesToDie: Int, minutesToTest: Int) = 14 | ceil(ln(buckets.toDouble()) / ln(minutesToTest.toDouble() / minutesToDie + 1)).toInt() 15 | } 16 | -------------------------------------------------------------------------------- /Algorithms/45_Jump_Game_II/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Integer} 3 | def jump(nums) 4 | jump_count = right = max_move = 0 5 | nums[0..-2].each_with_index do |jumps, left| 6 | max_move = [max_move, left + jumps].max 7 | if left == right 8 | left, right = right, max_move 9 | jump_count += 1 10 | end 11 | end 12 | jump_count 13 | end 14 | -------------------------------------------------------------------------------- /Algorithms/461_Hamming_Distance/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Solution { 5 | public: 6 | int hammingDistance(int x, int y) { 7 | int i = x ^ y, a = 0; 8 | for (; i > 2; a += i % 2, i >>= 1); 9 | return a + (i > 0); 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /Algorithms/462_Minimum_Moves_to_Equal_Array_Elements_II/Solution.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Solution { 4 | public int minMoves2(int[] nums) { 5 | Arrays.sort(nums); 6 | int median = nums[nums.length >> 1]; 7 | return Arrays.stream(nums).map(x -> Math.abs(x - median)).sum(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Algorithms/476_Number_Complement/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int findComplement(int num) { 8 | uint32_t k = 1; 9 | while ((k <<= 1) <= num); 10 | return num ^ (k - 1); 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /Algorithms/485_Max_Consecutive_Ones/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun findMaxConsecutiveOnes(nums: IntArray) = nums.joinToString("") 3 | .split("0") 4 | .map { it.length } 5 | .max()!! 6 | } 7 | -------------------------------------------------------------------------------- /Algorithms/48_Rotate_Image/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[][]} matrix 2 | # @return {Void} Do not return anything, modify matrix in-place instead. 3 | def rotate(matrix) 4 | matrix, n = matrix.reverse!, matrix.length 5 | (0...n).each do |i| 6 | (i + 1...n).each do |j| 7 | matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /Algorithms/49_Group_Anagrams/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {String[]} strs 2 | # @return {String[][]} 3 | def group_anagrams(strs) 4 | anagram = Hash.new [] 5 | strs.each { |s| anagram[s.each_char.sort_by { |c| c.chr }.join('')] += [s] } 6 | anagram.values 7 | end 8 | 9 | 10 | p group_anagrams(%w(eat tea tan ate nat bat)) -------------------------------------------------------------------------------- /Algorithms/500_Keyboard_Row/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun findWords(words: Array) = arrayOf("qwertyuiop".toSet(), "asdfghjkl".toSet(), "zxcvbnm".toSet()).let { rows -> 3 | words.filter { 4 | it.toLowerCase() 5 | .toSet() 6 | .run { rows[0].containsAll(this) || rows[1].containsAll(this) || rows[2].containsAll(this) } 7 | }.toTypedArray() 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Algorithms/506_Relative_Ranks/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun findRelativeRanks(score: IntArray) = score.sortedDescending() 3 | .zip(score.indices) 4 | .associate { 5 | it.first to when (it.second) { 6 | 0 -> "Gold Medal" 7 | 1 -> "Silver Medal" 8 | 2 -> "Bronze Medal" 9 | else -> "${it.second + 1}" 10 | } 11 | }.run { score.map { get(it)!! } } 12 | .toTypedArray() 13 | } 14 | -------------------------------------------------------------------------------- /Algorithms/509_Fibonacci_Number/solution.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fib(int N){ 4 | int a = 0, b = 1, c; 5 | for (int i = 0; i < N; i++) { 6 | c = a; 7 | a = b; 8 | b = a + c; 9 | } 10 | return a; 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/518_Coin_Change_2/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func change(amount int, coins []int) int { 4 | d := [5001]int{1} 5 | for _, coin := range coins { 6 | for i := coin; i <= amount; i++ { 7 | d[i] += d[i-coin] 8 | } 9 | } 10 | return d[amount] 11 | } -------------------------------------------------------------------------------- /Algorithms/520_Detect_Capital/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-09-18 6 | */ 7 | class Solution { 8 | fun detectCapitalUse(word: String) = word.all { it.isUpperCase() } || 9 | word.all { it.isLowerCase() } || 10 | (word.first().isUpperCase() && word.drop(1).all { it.isLowerCase() }) 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/524_Longest_Word_in_Dictionary_through_Deleting/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun findLongestWord(s: String, d: List): String = 3 | d.sortedWith(Comparator { x, y -> if (x.length == y.length) x.compareTo(y) else y.length - x.length }) 4 | .find { 5 | var (i, j) = 0 to 0 6 | while (i < s.length && j < it.length) { 7 | if (s[i++] == it[j]) ++j 8 | } 9 | j == it.length 10 | } 11 | .orEmpty() 12 | } -------------------------------------------------------------------------------- /Algorithms/525_Contiguous_Array/solution.py: -------------------------------------------------------------------------------- 1 | from typing import * 2 | 3 | 4 | class Solution: 5 | def findMaxLength(self, nums: List[int]) -> int: 6 | pos_of_val = {0: -1} 7 | max_len, val = 0, 0 8 | 9 | for cur_pos, n in enumerate(nums, 1): 10 | val += 1 if n else -1 11 | if val in pos_of_val: 12 | max_len = max(max_len, cur_pos - pos_of_val[val]) 13 | else: 14 | pos_of_val[val] = cur_pos 15 | 16 | return max_len 17 | -------------------------------------------------------------------------------- /Algorithms/53_Maximum_Subarray/solution.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | 4 | class Solution: 5 | def maxSubArray(self, nums: List[int]) -> int: 6 | for i in range(1, len(nums)): 7 | nums[i] += nums[i - 1] if nums[i - 1] > 0 else 0 8 | return max(nums) 9 | -------------------------------------------------------------------------------- /Algorithms/540_Single_Element_in_a_Sorted_Array/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func singleNonDuplicate(nums []int) int { 4 | sum := 0 5 | for i, num := range nums { 6 | if i%2 == 0 { 7 | sum += num 8 | } else { 9 | sum -= num 10 | } 11 | } 12 | return sum 13 | } 14 | -------------------------------------------------------------------------------- /Algorithms/544_Output_Contest_Matches/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun findContestMatch(n: Int): String { 3 | var seq: Array = (1..n).map { it.toString() }.toTypedArray() 4 | var k = n 5 | while (k > 1) { 6 | seq = 0.until(seq.size shr 1) 7 | .map { "(${seq[it]},${seq[seq.size - it - 1]})" } 8 | .toTypedArray() 9 | k = k shr 1 10 | } 11 | return seq.first() 12 | } 13 | } -------------------------------------------------------------------------------- /Algorithms/551_Student_Attendance_Record_I/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-12-06 6 | */ 7 | class Solution { 8 | fun checkRecord(s: String) = 9 | s.count { it == 'A' } < 2 && !s.contains("LLL") 10 | } 11 | -------------------------------------------------------------------------------- /Algorithms/55_Jump_Game/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Boolean} 3 | def can_jump(nums) 4 | unreachable = 0 5 | nums[0..-2].reverse_each do |n| 6 | unreachable = if n == 0 7 | unreachable + 1 8 | else 9 | n > unreachable ? 0 : unreachable + 1 10 | end 11 | end 12 | unreachable == 0 13 | end 14 | -------------------------------------------------------------------------------- /Algorithms/560_Subarray_Sum_Equals_K/solution.py: -------------------------------------------------------------------------------- 1 | from typing import * 2 | from collections import defaultdict 3 | 4 | 5 | class Solution: 6 | def subarraySum(self, nums: List[int], k: int) -> int: 7 | cnt, acc, sum_cache = 0, 0, defaultdict(lambda: 0) 8 | for n in nums: 9 | acc += n 10 | cnt += (acc == k) + sum_cache[acc - k] 11 | sum_cache[acc] += 1 12 | return cnt 13 | -------------------------------------------------------------------------------- /Algorithms/561_Array_Partition_I/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun arrayPairSum(nums: IntArray) = nums.sorted() 3 | .zip(nums.indices) 4 | .filter { it.second % 2 == 0 } 5 | .map { it.first } 6 | .sum() 7 | } 8 | -------------------------------------------------------------------------------- /Algorithms/565_Array_Nesting/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun arrayNesting(nums: IntArray) = nums.indices.map { 3 | var (j, len) = it to 0 4 | while (nums[j] != -1) { 5 | j = nums[j].apply { nums[j] = -1 } 6 | ++len 7 | } 8 | len 9 | }.max()!! 10 | } 11 | -------------------------------------------------------------------------------- /Algorithms/575_Distribute_Candies/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def distributeCandies(candyType: Array[Int]): Int = 3 | scala.math.min(candyType.distinct.length, candyType.length >> 1) 4 | } -------------------------------------------------------------------------------- /Algorithms/58_Length_of_Last_Word/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def lengthOfLastWord(self, s: str) -> int: 3 | return len(s.strip().split(' ')[-1:][0]) 4 | -------------------------------------------------------------------------------- /Algorithms/594_Longest_Harmonious_Subsequence/Solution.kt: -------------------------------------------------------------------------------- 1 | import kotlin.math.max 2 | 3 | class Solution { 4 | fun findLHS(nums: IntArray): Int = nums.groupBy { it } 5 | .mapValues { it.value.size } 6 | .withDefault { 0 } 7 | .run { 8 | map { 9 | max(this.getValue(it.key + 1), this.getValue(it.key - 1)) 10 | .run { if (this == 0) 0 else this + it.value } 11 | }.max()!! 12 | } 13 | } -------------------------------------------------------------------------------- /Algorithms/609_Find_Duplicate_File_in_System/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def findDuplicate(paths: Array[String]): List[List[String]] = paths.map(_.split(" ")) 3 | .flatMap(xs => xs.tail 4 | .flatMap(_.split(" ")) 5 | .map(_.replace(")", "").split("\\(")) 6 | .map(x => (x(1), s"${xs(0)}/${x(0)}")) 7 | ).groupMap(_._1)(_._2) 8 | .filter(_._2.length > 1) 9 | .map(_._2.toList) 10 | .toList 11 | } -------------------------------------------------------------------------------- /Algorithms/60_Permutation_Sequence/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} n 2 | # @param {Integer} k 3 | # @return {String} 4 | def get_permutation(n, k) 5 | divisor, k = 1, k - 1 6 | nums, idx = Array.new(n) { |a| a + 1 }, Array.new(n) { |_| 0 } 7 | 8 | (1..n).each do |place| 9 | break if k / divisor == 0 10 | idx[n - place], divisor = (k / divisor) % place, divisor * place 11 | end 12 | 13 | idx.map { |i| nums.delete_at(i) }.join 14 | end -------------------------------------------------------------------------------- /Algorithms/621_Task_Scheduler/Solution.kt: -------------------------------------------------------------------------------- 1 | import kotlin.math.max 2 | 3 | class Solution { 4 | fun leastInterval(tasks: CharArray, n: Int): Int = 5 | tasks.fold(mutableMapOf(), { acc, c -> acc.merge(c, 1, Integer::sum); acc }) 6 | .values 7 | .sortedWith(Comparator { a, b -> b.compareTo(a) }) 8 | .run { this.filter { it == this.first() } } 9 | .let { max(it.size + (it.first() - 1) * (n + 1), tasks.size) } 10 | } -------------------------------------------------------------------------------- /Algorithms/624_Maximum_Distance_in_Arrays/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def maxDistance(arrays: List[List[Int]]): Int = { 3 | val minMax = arrays.map(xs => Array(xs.head, if (xs.length == 1) xs.head else xs.last)).toArray 4 | var maxDist = -10000 5 | for (i <- minMax.indices; j <- minMax.indices) { 6 | if (i != j) maxDist = math.max(maxDist, math.abs(minMax(i)(0) - minMax(j)(1))) 7 | } 8 | maxDist 9 | } 10 | } -------------------------------------------------------------------------------- /Algorithms/62_Unique_Paths/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} m 2 | # @param {Integer} n 3 | # @return {Integer} 4 | def unique_paths(m, n) 5 | a = Array.new(m) { |_| 1 } 6 | (n - 1).times.each do |_| 7 | b = Array.new(m) { |i| i == 0 ? 1 : 0 } 8 | (1...m).each { |i| b[i] = b[i - 1] + a[i] } 9 | a = b 10 | end 11 | a[-1] 12 | end -------------------------------------------------------------------------------- /Algorithms/645_Set_Mismatch/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func findErrorNums(nums []int) []int { 4 | freq := make(map[int]int) 5 | for i := 1; i <= len(nums); i++ { 6 | freq[i] = 1 7 | } 8 | for _, n := range nums { 9 | freq[n]-- 10 | } 11 | dup, lost := 0, 0 12 | for k, v := range freq { 13 | if v == -1 { 14 | dup = k 15 | } else if v == 1 { 16 | lost = k 17 | } 18 | } 19 | return []int{dup, lost} 20 | } 21 | -------------------------------------------------------------------------------- /Algorithms/648_Replace_Words/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string[]} dictionary 3 | * @param {string} sentence 4 | * @return {string} 5 | */ 6 | const replaceWords = (dictionary, sentence) => { 7 | dictionary = dictionary.sort((a, b) => a.length - b.length); 8 | return sentence.split(" ") 9 | .map(s => { 10 | const sLen = s.length; 11 | for (const w of dictionary) { 12 | if (sLen > w.length && s.startsWith(w)) { 13 | return w 14 | } 15 | } 16 | return s; 17 | }).join(" "); 18 | }; 19 | -------------------------------------------------------------------------------- /Algorithms/64_Minimum_Path_Sum/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[][]} grid 2 | # @return {Integer} 3 | def min_path_sum(grid) 4 | (0..grid[0].length - 2).each { |i| grid[0][i + 1] += grid[0][i] } 5 | (0..grid.length - 2).each { |i| grid[i + 1][0] += grid[i][0] } 6 | (1..grid.length - 1).each { |i| (1..grid[0].length - 1).each { |j| grid[i][j] += [grid[i - 1][j], grid[i][j - 1]].min } } 7 | grid[-1][-1] 8 | end -------------------------------------------------------------------------------- /Algorithms/658_Find_K_Closest_Elements/Solution.kt: -------------------------------------------------------------------------------- 1 | mport kotlin.math.abs 2 | 3 | class Solution { 4 | fun findClosestElements(arr: IntArray, k: Int, x: Int): List = arr.map { Pair(abs(it - x), it) } 5 | .sortedWith(Comparator { x, y -> if (x.first == y.first) x.second - y.second else x.first - y.first }) 6 | .map { it.second } 7 | .take(k) 8 | .sorted() 9 | } 10 | -------------------------------------------------------------------------------- /Algorithms/66_Plus_One/solution.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | 4 | class Solution: 5 | def plusOne(self, digits: List[int]) -> List[int]: 6 | return list(str(int(''.join(map(lambda i: str(i), digits))) + 1)) 7 | -------------------------------------------------------------------------------- /Algorithms/67_Add_Binary/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def addBinary(self, a: str, b: str) -> str: 3 | return '{0:b}'.format(int(a, 2) + int(b, 2)) 4 | -------------------------------------------------------------------------------- /Algorithms/680_Valid_Palindrome_II/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun validPalindrome(s: String, deleted: Boolean = false): Boolean { 3 | var (left, right) = -1 to s.length 4 | while (++left <= --right) { 5 | if (s[left] != s[right]) { 6 | return !deleted && (validPalindrome(s.substring(left, right), true) || 7 | validPalindrome(s.substring(left + 1, right + 1), true)) 8 | } 9 | } 10 | return true 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Algorithms/682_Baseball_Game/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun calPoints(ops: Array) = mutableListOf().apply { 3 | ops.forEach { x -> 4 | when (x) { 5 | "+" -> this += takeLast(2).sum() 6 | "D" -> this += last() * 2 7 | "C" -> removeAt(size - 1) 8 | else -> this += x.toInt() 9 | } 10 | } 11 | }.sum() 12 | } 13 | -------------------------------------------------------------------------------- /Algorithms/69_Sqrt(x)/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def mySqrt(self, x: int) -> int: 3 | r = x 4 | while r * r > x: 5 | r = (r + x // r) // 2 6 | return r 7 | -------------------------------------------------------------------------------- /Algorithms/704_Binary_Search/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def search(nums: Array[Int], target: Int): Int = { 3 | @scala.annotation.tailrec 4 | def binarySearch(left: Int, right: Int): Int = if (left > right) -1 5 | else { 6 | val mid = (left + right) >> 1 7 | if (nums(mid) == target) mid 8 | else if (nums(mid) < target) binarySearch(mid + 1, right) 9 | else binarySearch(left, mid - 1) 10 | } 11 | binarySearch(0, nums.length - 1) 12 | } 13 | } -------------------------------------------------------------------------------- /Algorithms/705_Design_HashSet/Solution.kt: -------------------------------------------------------------------------------- 1 | class MyHashSet { 2 | 3 | private val hashSet = BooleanArray(1000001) { false } 4 | 5 | fun add(key: Int) { 6 | hashSet[key] = true 7 | } 8 | 9 | fun remove(key: Int) { 10 | hashSet[key] = false 11 | } 12 | 13 | fun contains(key: Int) = hashSet[key] 14 | } 15 | 16 | /** 17 | * Your MyHashSet object will be instantiated and called as such: 18 | * var obj = MyHashSet() 19 | * obj.add(key) 20 | * obj.remove(key) 21 | * var param_3 = obj.contains(key) 22 | */ 23 | -------------------------------------------------------------------------------- /Algorithms/709_To_Lower_Case/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | string toLowerCase(string str) { 8 | for (char& ch : str) { 9 | if (64 < ch && ch < 91) { 10 | ch += 32; 11 | } 12 | } 13 | return str; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /Algorithms/70_Climbing_Stairs/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | 3 | public int climbStairs(int n) { 4 | int a = 1, b = 1; 5 | for (int i = 0; i < n; i++) { 6 | int c = a + b; 7 | a = b; 8 | b = c; 9 | } 10 | return a; 11 | } 12 | } -------------------------------------------------------------------------------- /Algorithms/70_Climbing_Stairs/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def climbStairs(self, n: int) -> int: 3 | a, b = 1, 2 4 | for i in range(1, n): 5 | a, b = b, a + b 6 | return a 7 | -------------------------------------------------------------------------------- /Algorithms/70_Climbing_Stairs/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} n 2 | # @return {Integer} 3 | def climb_stairs(n) 4 | a = b = 1 5 | (2..n).each { |_| a, b = b, a + b } 6 | b 7 | end -------------------------------------------------------------------------------- /Algorithms/713_Subarray_Product_Less_Than_K/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun numSubarrayProductLessThanK(nums: IntArray, k: Int): Int { 3 | if (k <= 1) { 4 | return 0 5 | } 6 | 7 | var (ans, left, prod) = Triple(0, 0, 1) 8 | for (right in nums.indices) { 9 | prod *= nums[right] 10 | while (prod >= k) { 11 | prod /= nums[left++] 12 | } 13 | ans += right - left + 1 14 | } 15 | return ans 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Algorithms/71_Simplify_Path/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {String} path 2 | # @return {String} 3 | def simplify_path(path) 4 | stk = [] 5 | path.split('/').reject { |_| _ == '.' or _ == '' }.each do |k| 6 | k == '..' ? stk.pop : stk << k 7 | end 8 | '/' + stk.join('/') 9 | end -------------------------------------------------------------------------------- /Algorithms/724_Find_Pivot_Index/Solution.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | class Solution { 4 | public int pivotIndex(int[] nums) { 5 | int lefts = 0, rights = Arrays.stream(nums).sum() - nums[0], n = nums.length - 1; 6 | for (int i = 0; i < n; ++i) { 7 | if (lefts == rights) { 8 | return i; 9 | } 10 | lefts += nums[i]; 11 | rights -= nums[i + 1]; 12 | } 13 | return lefts == rights ? n : -1; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Algorithms/739_Daily_Temperatures/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} t 2 | # @return {Integer[]} 3 | def daily_temperatures(t) 4 | stk, ans = [0], Array.new(t.length) { |_| 0 } 5 | (1...t.length).each do |i| 6 | ans[stk[-1]] = i - stk.pop while !stk.empty? and t[stk[-1]] < t[i] 7 | stk << i 8 | end 9 | ans 10 | end -------------------------------------------------------------------------------- /Algorithms/744_Find_Smallest_Letter_Greater_Than_Target/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun nextGreatestLetter(letters: CharArray, target: Char): Char { 3 | for (c in letters) { 4 | if (c > target) { 5 | return c 6 | } 7 | } 8 | return letters[0] 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Algorithms/746_Min_Cost_Climbing_Stairs/Solution.kt: -------------------------------------------------------------------------------- 1 | import kotlin.math.min 2 | 3 | class Solution { 4 | fun minCostClimbingStairs(cost: IntArray): Int = cost.indices.forEach { i -> 5 | cost[i] += if (i < 2) 0 else min(cost[i - 2], cost[i - 1]) 6 | }.let { min(cost[cost.size - 2], cost.last()) } 7 | } 8 | -------------------------------------------------------------------------------- /Algorithms/74_Search_a_2D_Matrix/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[][]} matrix 2 | # @param {Integer} target 3 | # @return {Boolean} 4 | def search_matrix(matrix, target) 5 | b_search(matrix.flatten, target) 6 | end 7 | 8 | def b_search(a, t) 9 | return false if a.empty? 10 | a[m = a.length / 2] == t ? true : (a[m] > t ? b_search(a[0...m], t) : b_search(a[m + 1..-1], t)) 11 | end -------------------------------------------------------------------------------- /Algorithms/750_Number_Of_Corner_Rectangles/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func countCornerRectangles(grid [][]int) int { 4 | acc := 0 5 | m, n := len(grid), len(grid[0]) 6 | 7 | for i := 0; i < m-1; i++ { 8 | for j := i + 1; j < m; j++ { 9 | cnt := 0 10 | for k := 0; k < n; k++ { 11 | cnt += grid[i][k] & grid[j][k] // count vertical line of rectangle (both 1) 12 | } 13 | acc += (cnt * (cnt - 1)) >> 1 // mathematical formula 14 | } 15 | } 16 | 17 | return acc 18 | } 19 | -------------------------------------------------------------------------------- /Algorithms/760_Find_Anagram_Mappings/Solution.scala: -------------------------------------------------------------------------------- 1 | object Solution { 2 | def anagramMappings(A: Array[Int], B: Array[Int]): Array[Int] = { 3 | val anagramMap = B.zipWithIndex.toMap 4 | A.map(anagramMap(_)) 5 | } 6 | } -------------------------------------------------------------------------------- /Algorithms/771_Jewels_and_Stones/solution.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/Algorithms/771_Jewels_and_Stones/solution.py -------------------------------------------------------------------------------- /Algorithms/781_Rabbits_in_Forest/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun numRabbits(answers: IntArray) = answers.groupBy { it } 3 | .mapValues { (k, v) -> v.size / (k + 1) + if (v.size % (k + 1) != 0) 1 else 0 } 4 | .map { (it.key + 1) * it.value } 5 | .sum() 6 | } 7 | -------------------------------------------------------------------------------- /Algorithms/788_Rotated_Digits/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | private val good = setOf(0, 1, 8) 3 | private val better = setOf(2, 5, 6, 9) 4 | private val rotatable = good + better 5 | 6 | fun rotatedDigits(n: Int) = (0..n).count { it.isRotatable() && it.hasAnyBetterElement() } 7 | 8 | private fun Int.isRotatable() = toString().all { rotatable.contains(it - '0') } 9 | 10 | private fun Int.hasAnyBetterElement() = toString().any { better.contains(it - '0') } 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/789_Escape_The_Ghosts/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun escapeGhosts(ghosts: Array, target: IntArray) = 3 | intArrayOf(0, 0).getDist(target) 4 | .let { mine -> ghosts.all { mine < it.getDist(target) } } 5 | 6 | private fun IntArray.getDist(target: IntArray) = 7 | kotlin.math.abs(first() - target.first()) + kotlin.math.abs(last() - target.last()) 8 | } 9 | -------------------------------------------------------------------------------- /Algorithms/78_Subsets/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Integer[][]} 3 | def subsets(nums) 4 | Subset.new(nums).subset 5 | end 6 | 7 | class Subset 8 | attr_reader :subset 9 | 10 | def initialize(nums) 11 | @nums, @len, @subset = nums, nums.length, [] 12 | dfs(-1, []) 13 | end 14 | 15 | private 16 | 17 | def dfs(cur, selected) 18 | @subset << selected.dup 19 | return if selected.length == @len 20 | (cur + 1...@len).each { |i| dfs(i, selected + [@nums[i]]) } 21 | end 22 | end -------------------------------------------------------------------------------- /Algorithms/791_Custom_Sort_String/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun customSortString(order: String, s: String) = order.withIndex() 3 | .associate { it.value to it.index } 4 | .withDefault { Int.MAX_VALUE } 5 | .run { 6 | s.asSequence() 7 | .sortedWith(Comparator { x, y -> getValue(x) - getValue(y) }) 8 | .joinToString("") 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Algorithms/796_Rotate_String/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun rotateString(s: String, goal: String) = s.length == goal.length && "$s$s".contains(goal) 3 | } 4 | -------------------------------------------------------------------------------- /Algorithms/7_Reverse_Integer/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun reverse(x: Int): Int { 3 | val num = ((if (x < 0) "-" else "") + x.toString().removePrefix("-").reversed()).toLong() 4 | return if (Int.MIN_VALUE <= num && num <= Int.MAX_VALUE) { 5 | num.toInt() 6 | } else { 7 | 0 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Algorithms/80_Remove_Duplicates_from_Sorted_Array_II/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Integer} 3 | def remove_duplicates(nums) 4 | i, len = 1, nums.length 5 | while i < len - 1 6 | l, m, r = nums[i - 1], nums[i], nums[i + 1] 7 | if l == m and m == r 8 | (i + 2...len).each { |j| nums[j - 1] = nums[j] } 9 | nums[(len = len - 1)] = nil 10 | else 11 | i += 1 12 | end 13 | end 14 | len 15 | end -------------------------------------------------------------------------------- /Algorithms/820_Short_Encoding_of_Words/solution.py: -------------------------------------------------------------------------------- 1 | from typing import * 2 | 3 | 4 | class Solution: 5 | def minimumLengthEncoding(self, words: List[str]) -> int: 6 | remains = set(words) 7 | for w in words: 8 | for i in range(1, len(w)): 9 | remains.discard(w[i:]) 10 | return sum(len(_) + 1 for _ in remains) 11 | -------------------------------------------------------------------------------- /Algorithms/824_Goat_Latin/solution.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | # @param [String] sentence 3 | # @return [String] 4 | def to_goat_latin(sentence) 5 | sentence.split(' ') 6 | .each_with_index 7 | .map { |x, i| ('aeiouAEIOU'.include?(x[0]) ? x : x[1, x.size] + x[0]) + "m#{(0...i + 2).map { 'a' }.join}" } 8 | .join(' ') 9 | end 10 | -------------------------------------------------------------------------------- /Algorithms/832_Flipping_an_Image/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | vector> flipAndInvertImage(vector>& A) { 8 | int n = A.size(), m = A[0].size(); 9 | for (int i = 0; i < n; i++) { 10 | vector tmp(m); 11 | for (int j = 0; j < m; j++) { 12 | tmp[m - j - 1] = (A[i][j] + 1) % 2; 13 | } 14 | A[i] = tmp; 15 | } 16 | return A; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /Algorithms/852_Peak_Index_in_a_Mountain_Array/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int peakIndexInMountainArray(vector& A) { 8 | int peek = -1; 9 | for (int i = 1; i < A.size(); i++) { 10 | if (A[i - 1] > A[i]) { 11 | peek = i - 1; 12 | break; 13 | } 14 | } 15 | return peek; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /Algorithms/876_Middle_of_the_Linked_List/solution.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * Definition for singly-linked list. 5 | * struct ListNode { 6 | * int val; 7 | * struct ListNode *next; 8 | * }; 9 | */ 10 | 11 | struct ListNode* middleNode(struct ListNode* head){ 12 | struct ListNode* nodes[100]; 13 | int n = 0; 14 | while (head) { 15 | nodes[n++] = head; 16 | head = head -> next; 17 | } 18 | return nodes[n / 2]; 19 | } 20 | -------------------------------------------------------------------------------- /Algorithms/881_Boats_to_Save_People/solution.ts: -------------------------------------------------------------------------------- 1 | function numRescueBoats(people: number[], limit: number): number { 2 | const sorted = people.sort((a, b) => a - b) 3 | let i = 0, j = sorted.length - 1, acc = 0 4 | 5 | for (; i < j; --j, ++acc) { 6 | if (sorted[i] + sorted[j] <= limit) { 7 | ++i 8 | } 9 | } 10 | 11 | return acc + (i == j ? 1 : 0) 12 | } 13 | -------------------------------------------------------------------------------- /Algorithms/884_Uncommon_Words_from_Two_Sentences/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @Blog: https://blog.naver.com/occidere 4 | * @Github: https://github.com/occidere 5 | * @since 2022-08-30 6 | */ 7 | class Solution { 8 | fun uncommonFromSentences(s1: String, s2: String) = "$s1 $s2".split(" ") 9 | .groupBy { it } 10 | .filter { it.value.size == 1 } 11 | .keys 12 | .toTypedArray() 13 | } 14 | -------------------------------------------------------------------------------- /Algorithms/896_Monotonic_Array/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @github https://github.com/occidere 4 | * @blog https://blog.naver.com/occidere 5 | * @since 2022-07-18 6 | */ 7 | class Solution { 8 | fun isMonotonic(nums: IntArray) = nums.toList() 9 | .zipWithNext() 10 | .run { all { it.first >= it.second } || all { it.first <= it.second } } 11 | } 12 | -------------------------------------------------------------------------------- /Algorithms/89_Gray_Code/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | vector grayCode(int n) { 8 | vector gray = vector({0}); 9 | for (int i = 0; i < n; ++i) { 10 | for (int j = gray.size(); j > 0; --j) { 11 | gray.push_back((gray[j - 1] | 1 << i)); 12 | } 13 | } 14 | return gray; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /Algorithms/921_Minimum_Add_to_Make_Parentheses_Valid/Solution.kt: -------------------------------------------------------------------------------- 1 | import java.util.* 2 | 3 | class Solution { 4 | fun minAddToMakeValid(s: String) = Stack().let { 5 | s.forEach { c -> 6 | if (c == ')') 7 | if (it.isNotEmpty() && it.peek() == '(') 8 | it.pop() 9 | else it.push(c) 10 | else 11 | it.push(c) 12 | } 13 | it.size 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Algorithms/929_Unique_Email_Addresses/solution.py: -------------------------------------------------------------------------------- 1 | from typing import * 2 | 3 | 4 | class Solution: 5 | def numUniqueEmails(self, emails: List[str]) -> int: 6 | processed_sets: Set[str] = set() 7 | for local, domain in map(lambda e: e.split('@'), emails): 8 | local = local.replace('.', '') 9 | plus = local.find('+') 10 | if plus != -1: 11 | local = local[0:plus] 12 | processed_sets.add('{}@{}'.format(local, domain)) 13 | return len(processed_sets) 14 | -------------------------------------------------------------------------------- /Algorithms/933_Number_of_Recent_Calls/RecentCounter.scala: -------------------------------------------------------------------------------- 1 | import scala.collection.mutable 2 | 3 | /** 4 | * @author occidere 5 | * @Blog: https://blog.naver.com/occidere 6 | * @Github: https://github.com/occidere 7 | * @since 2020. 10. 01. 8 | */ 9 | class RecentCounter { 10 | private val counter = mutable.Queue[Int]() 11 | 12 | def ping(t: Int): Int = { 13 | counter += t 14 | while (t - 3000 > counter.head) counter.dequeue() 15 | counter.size 16 | } 17 | } -------------------------------------------------------------------------------- /Algorithms/942_DI_String_Match/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Solution { 7 | public: 8 | vector diStringMatch(string S) { 9 | vector ans; 10 | int i = 0, j = S.length(); 11 | for (char& c : S) { 12 | ans.push_back(c == 'I' ? i++ : j--); 13 | } 14 | ans.push_back(i); 15 | return ans; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /Algorithms/946_Validate_Stack_Sequences/Solution.java: -------------------------------------------------------------------------------- 1 | import java.util.Stack; 2 | 3 | class Solution { 4 | 5 | public boolean validateStackSequences(int[] pushed, int[] popped) { 6 | Stack stk = new Stack<>(); 7 | int i = 0; 8 | for (int element : pushed) { 9 | stk.push(element); 10 | while (!stk.isEmpty() && stk.peek() == popped[i]) { 11 | stk.pop(); 12 | ++i; 13 | } 14 | } 15 | return stk.isEmpty(); 16 | } 17 | } -------------------------------------------------------------------------------- /Algorithms/946_Validate_Stack_Sequences/Solution.kt: -------------------------------------------------------------------------------- 1 | import java.util.* 2 | 3 | class Solution { 4 | fun validateStackSequences(pushed: IntArray, popped: IntArray): Boolean = 5 | Stack().also { 6 | var i = 0 7 | for (element in pushed) { 8 | it.push(element) 9 | while (it.isNotEmpty() && it.peek() == popped[i]) { 10 | it.pop() 11 | ++i 12 | } 13 | } 14 | }.isEmpty() 15 | } -------------------------------------------------------------------------------- /Algorithms/946_Validate_Stack_Sequences/Solution.scala: -------------------------------------------------------------------------------- 1 | import scala.collection.mutable 2 | 3 | object Solution { 4 | def validateStackSequences(pushed: Array[Int], popped: Array[Int]): Boolean = { 5 | val stk = mutable.Stack[Int]() 6 | 7 | var i = 0 8 | for (element <- pushed) { 9 | stk.push(element) 10 | while (stk.nonEmpty && stk.top == popped(i)) { 11 | stk.pop() 12 | i += 1 13 | } 14 | } 15 | 16 | stk.isEmpty 17 | } 18 | } -------------------------------------------------------------------------------- /Algorithms/946_Validate_Stack_Sequences/solution.go: -------------------------------------------------------------------------------- 1 | func validateStackSequences(pushed []int, popped []int) bool { 2 | stk := make([]int, 0, 1000) 3 | i := 0 4 | 5 | for _, element := range pushed { 6 | stk = append(stk, element) 7 | for len(stk) > 0 && stk[len(stk)-1] == popped[i] { 8 | stk = stk[:len(stk)-1] 9 | i++ 10 | } 11 | } 12 | 13 | return len(stk) == 0 14 | } 15 | -------------------------------------------------------------------------------- /Algorithms/946_Validate_Stack_Sequences/solution.py: -------------------------------------------------------------------------------- 1 | from typing import * 2 | 3 | 4 | class Solution: 5 | def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool: 6 | stk: List[int] = [] 7 | i = 0 8 | for element in pushed: 9 | stk.append(element) 10 | while stk and stk[-1] == popped[i]: 11 | stk.pop() 12 | i += 1 13 | return not stk 14 | -------------------------------------------------------------------------------- /Algorithms/946_Validate_Stack_Sequences/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} pushed 2 | # @param {Integer[]} popped 3 | # @return {Boolean} 4 | def validate_stack_sequences(pushed, popped) 5 | stk, i = [], 0 6 | pushed.each do |element| 7 | stk << element 8 | while !stk.empty? && stk[-1] == popped[i] 9 | stk.pop 10 | i += 1 11 | end 12 | end 13 | stk.empty? 14 | end -------------------------------------------------------------------------------- /Algorithms/961_N-Repeated_Element_in_Size_2N_Array/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int repeatedNTimes(vector& A) { 8 | int freq[10000] = {0}, n = A.size() / 2; 9 | for (int& a : A) { 10 | freq[a]++; 11 | if (freq[a] == n) { 12 | return a; 13 | } 14 | } 15 | return 0; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /Algorithms/96_Unique_Binary_Search_Trees/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func numTrees(n int) int { 4 | d := make([]int, n+1, n+1) 5 | d[0] = 1 6 | return dp(n, d) 7 | } 8 | 9 | func dp(n int, d []int) int { 10 | if d[n] == 0 { 11 | for i := 0; i < n; i++ { 12 | d[n] += d[i] * dp(n-i-1, d) 13 | } 14 | } 15 | return d[n] 16 | } -------------------------------------------------------------------------------- /Algorithms/976_Largest_Perimeter_Triangle/Solution.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * @author occidere 3 | * @github https://github.com/occidere 4 | * @blog https://blog.naver.com/occidere 5 | * @since 2022-07-06 6 | */ 7 | class Solution { 8 | fun largestPerimeter(nums: IntArray): Int { 9 | nums.sortDescending() 10 | for (i in 0 until nums.size - 2) { 11 | if (nums[i] < nums[i + 1] + nums[i + 2]) { 12 | return nums[i] + nums[i + 1] + nums[i + 2] 13 | } 14 | } 15 | return 0 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Algorithms/991_Broken_Calculator/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func brokenCalc(x int, y int) int { 4 | cnt := 0 5 | for ; x < y; cnt++ { 6 | if y%2 == 1 { 7 | y++ 8 | } else { 9 | y >>= 1 10 | } 11 | } 12 | return cnt + x - y 13 | } 14 | -------------------------------------------------------------------------------- /Challenge/30-Day_LeetCoding_Challenge/Week_1:_April_1st–April_7th/122_Best_Time_to_Buy_and_Sell_Stock_II/solution.py: -------------------------------------------------------------------------------- 1 | from typing import * 2 | 3 | 4 | class Solution: 5 | def maxProfit(self, prices: List[int]) -> int: 6 | max_profit = 0 7 | for i in range(1, len(prices)): 8 | max_profit += prices[i] - prices[i - 1] if prices[i] > prices[i - 1] else 0 9 | return max_profit 10 | -------------------------------------------------------------------------------- /Challenge/30-Day_LeetCoding_Challenge/Week_1:_April_1st–April_7th/136_Single_Number/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int singleNumber(int[] nums) { 3 | int a = 0; 4 | for (int num : nums) { 5 | a ^= num; 6 | } 7 | return a; 8 | } 9 | } -------------------------------------------------------------------------------- /Challenge/30-Day_LeetCoding_Challenge/Week_1:_April_1st–April_7th/136_Single_Number/solution.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | 4 | class Solution: 5 | def singleNumber(self, nums: List[int]) -> int: 6 | b = 0 7 | for k in nums: 8 | b ^= k 9 | return b 10 | -------------------------------------------------------------------------------- /Challenge/30-Day_LeetCoding_Challenge/Week_1:_April_1st–April_7th/136_Single_Number/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Integer} 3 | def single_number(nums) 4 | a = 0 5 | nums.each { |n| a ^= n } 6 | a 7 | end -------------------------------------------------------------------------------- /Challenge/30-Day_LeetCoding_Challenge/Week_1:_April_1st–April_7th/202_Happy_Number/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer} n 2 | # @return {Boolean} 3 | def is_happy(n) 4 | visit = {} 5 | visit[n] = n = n.to_s.each_char.inject(0) { |sum, s| sum + (s.to_i ** 2) } while n != 1 and !visit[n] 6 | n == 1 7 | end 8 | -------------------------------------------------------------------------------- /Challenge/30-Day_LeetCoding_Challenge/Week_1:_April_1st–April_7th/283_Move_Zeroes/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Void} Do not return anything, modify nums in-place instead. 3 | def move_zeroes(nums) 4 | (l = 0...nums.length).each do |r| 5 | if nums[l] == 0 and nums[r] != 0 6 | nums[l], nums[r] = nums[r], nums[l] 7 | l += 1 8 | elsif nums[l] != 0 and nums[r] == 0 9 | l = r 10 | end 11 | end 12 | end -------------------------------------------------------------------------------- /Challenge/30-Day_LeetCoding_Challenge/Week_1:_April_1st–April_7th/49_Group_Anagrams/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {String[]} strs 2 | # @return {String[][]} 3 | def group_anagrams(strs) 4 | anagram = Hash.new [] 5 | strs.each { |s| anagram[s.each_char.sort_by { |c| c.chr }.join('')] += [s] } 6 | anagram.values 7 | end 8 | 9 | 10 | p group_anagrams(%w(eat tea tan ate nat bat)) -------------------------------------------------------------------------------- /Challenge/30-Day_LeetCoding_Challenge/Week_1:_April_1st–April_7th/53_Maximum_Subarray/solution.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | 4 | class Solution: 5 | def maxSubArray(self, nums: List[int]) -> int: 6 | for i in range(1, len(nums)): 7 | nums[i] += nums[i - 1] if nums[i - 1] > 0 else 0 8 | return max(nums) 9 | -------------------------------------------------------------------------------- /Challenge/30-Day_LeetCoding_Challenge/Week_2:_April_8th–April_14th/1046_Last_Stone_Weight/solution.py: -------------------------------------------------------------------------------- 1 | from typing import * 2 | import heapq 3 | 4 | 5 | class Solution: 6 | def lastStoneWeight(self, stones: List[int]) -> int: 7 | pq = [-s for s in stones] 8 | heapq.heapify(pq) 9 | while len(pq) > 1: 10 | heapq.heappush(pq, -abs(heapq.heappop(pq) - heapq.heappop(pq))) 11 | return -pq[0] if pq else 0 12 | -------------------------------------------------------------------------------- /Challenge/30-Day_LeetCoding_Challenge/Week_2:_April_8th–April_14th/Perform_String_Shifts/solution.py: -------------------------------------------------------------------------------- 1 | from typing import * 2 | 3 | 4 | class Solution: 5 | def stringShift(self, s: str, shift: List[List[int]]) -> str: 6 | pos, s_len = 0, len(s) 7 | for direction, count in shift: 8 | pos += -count if direction else count 9 | pos += s_len if pos < 0 else 0 10 | pos %= s_len 11 | return s[pos:s_len] + s[0:pos] 12 | -------------------------------------------------------------------------------- /Challenge/30-Day_LeetCoding_Challenge/Week_3:_April_15th-April_21st/238_Product_of_Array_Except_Self/solution.py: -------------------------------------------------------------------------------- 1 | from typing import * 2 | 3 | 4 | class Solution: 5 | def productExceptSelf(self, nums: List[int]) -> List[int]: 6 | right, res = 1, [1 for _ in range(len(nums))] 7 | for i in range(1, len(nums)): 8 | res[i] *= nums[i - 1] * res[i - 1] 9 | for i in range(len(nums) - 2, -1, -1): 10 | res[i] *= nums[i + 1] * right 11 | right *= nums[i + 1] 12 | return res 13 | -------------------------------------------------------------------------------- /Challenge/30-Day_LeetCoding_Challenge/Week_4:_April_22nd–April_28th/55_Jump_Game/solution.rb: -------------------------------------------------------------------------------- 1 | # @param {Integer[]} nums 2 | # @return {Boolean} 3 | def can_jump(nums) 4 | unreachable = 0 5 | nums[0..-2].reverse_each do |n| 6 | unreachable = if n == 0 7 | unreachable + 1 8 | else 9 | n > unreachable ? 0 : unreachable + 1 10 | end 11 | end 12 | unreachable == 0 13 | end 14 | -------------------------------------------------------------------------------- /Challenge/30-Day_LeetCoding_Challenge/Week_4:_April_22nd–April_28th/560_Subarray_Sum_Equals_K/solution.py: -------------------------------------------------------------------------------- 1 | from typing import * 2 | from collections import defaultdict 3 | 4 | 5 | class Solution: 6 | def subarraySum(self, nums: List[int], k: int) -> int: 7 | cnt, acc, sum_cache = 0, 0, defaultdict(lambda: 0) 8 | for n in nums: 9 | acc += n 10 | cnt += (acc == k) + sum_cache[acc - k] 11 | sum_cache[acc] += 1 12 | return cnt 13 | -------------------------------------------------------------------------------- /Challenge/June_LeetCoding_Challenge/Week_1:_June_1st–June_7th/1029_Two_City_Scheduling/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "sort" 4 | 5 | func twoCitySchedCost(costs [][]int) int { 6 | sort.Slice(costs, func(i, j int) bool { 7 | return costs[i][0]-costs[i][1] < costs[j][0]-costs[j][1] 8 | }) 9 | 10 | minCost, half := 0, len(costs)>>1 11 | for i := 0; i < len(costs); i++ { 12 | minCost += costs[i][i/half] 13 | } 14 | return minCost 15 | } 16 | -------------------------------------------------------------------------------- /Challenge/June_LeetCoding_Challenge/Week_1:_June_1st–June_7th/226_Invert_Binary_Tree/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | /** 4 | * Definition for a binary tree node. 5 | * type TreeNode struct { 6 | * Val int 7 | * Left *TreeNode 8 | * Right *TreeNode 9 | * } 10 | */ 11 | func invertTree(root *TreeNode) *TreeNode { 12 | if root != nil { 13 | invertTree(root.Left) 14 | invertTree(root.Right) 15 | root.Left, root.Right = root.Right, root.Left 16 | } 17 | return root 18 | } -------------------------------------------------------------------------------- /Challenge/June_LeetCoding_Challenge/Week_1:_June_1st–June_7th/237_Delete_Node_in_a_Linked_List/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | /** 4 | * Definition for singly-linked list. 5 | * type ListNode struct { 6 | * Val int 7 | * Next *ListNode 8 | * } 9 | */ 10 | func deleteNode(node *ListNode) { 11 | *node = *node.Next 12 | } -------------------------------------------------------------------------------- /Challenge/June_LeetCoding_Challenge/Week_1:_June_1st–June_7th/344_Reverse_String/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | void reverseString(vector& s) { 8 | int len = s.size(); 9 | int half = len / 2; 10 | for (int i = 0; i < half; i++) { 11 | char ch = s[i]; 12 | s[i] = s[len - i - 1]; 13 | s[len - i - 1] = ch; 14 | } 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /Challenge/June_LeetCoding_Challenge/Week_1:_June_1st–June_7th/344_Reverse_String/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func reverseString(s []byte) { 6 | for i := 0; i < len(s)>>1; i++ { 7 | s[i], s[len(s)-i-1] = s[len(s)-i-1], s[i] 8 | } 9 | } 10 | 11 | func main() { 12 | s := []byte{'a', 'b', 'c', 'd', 'e'} 13 | reverseString(s) 14 | fmt.Println(s) 15 | } 16 | -------------------------------------------------------------------------------- /Challenge/June_LeetCoding_Challenge/Week_1:_June_1st–June_7th/518_Coin_Change_2/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func change(amount int, coins []int) int { 4 | d := [5001]int{1} 5 | for _, coin := range coins { 6 | for i := coin; i <= amount; i++ { 7 | d[i] += d[i-coin] 8 | } 9 | } 10 | return d[amount] 11 | } -------------------------------------------------------------------------------- /Challenge/June_LeetCoding_Challenge/Week_2:_June_8th–June_14th/231_Power_of_Two/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func isPowerOfTwo(n int) bool { 4 | return n != 0 && (n & (n - 1) == 0) 5 | } -------------------------------------------------------------------------------- /Challenge/June_LeetCoding_Challenge/Week_2:_June_8th–June_14th/35_Search_Insert_Position/Solution.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | 4 | class Solution: 5 | def searchInsert(self, nums: List[int], target: int) -> int: 6 | return len([x for x in nums if x < target]) 7 | -------------------------------------------------------------------------------- /Challenge/June_LeetCoding_Challenge/Week_2:_June_8th–June_14th/35_Search_Insert_Position/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func searchInsert(nums []int, target int) int { 4 | i := 0 5 | for ; i < len(nums) && nums[i] < target; i++ {} 6 | return i 7 | } -------------------------------------------------------------------------------- /Challenge/May_LeetCoding_Challenge/Week_1:_May_1st–May_7th/169_Majority_Element/Solution.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun majorityElement(nums: IntArray): Int { 3 | val freq = HashMap() 4 | nums.forEach { it -> freq.merge(it, 1, Integer::sum) } 5 | val k = nums.size / 2 6 | for (f in freq) { 7 | if (f.value > k) { 8 | return f.key 9 | } 10 | } 11 | return 0 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Challenge/May_LeetCoding_Challenge/Week_1:_May_1st–May_7th/383_Ransom_Note/solution.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | 3 | 4 | class Solution: 5 | def canConstruct(self, ransomNote: str, magazine: str) -> bool: 6 | buf = defaultdict(lambda: 0) 7 | 8 | for s in magazine: 9 | buf[s] += 1 10 | 11 | for s in ransomNote: 12 | if buf[s] < 1: 13 | return False 14 | else: 15 | buf[s] -= 1 16 | 17 | return True; 18 | -------------------------------------------------------------------------------- /Challenge/May_LeetCoding_Challenge/Week_1:_May_1st–May_7th/476_Number_Complement/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int findComplement(int num) { 8 | uint32_t k = 1; 9 | while ((k <<= 1) <= num); 10 | return num ^ (k - 1); 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /Challenge/May_LeetCoding_Challenge/Week_1:_May_1st–May_7th/771_Jewels_and_Stones/solution.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/Challenge/May_LeetCoding_Challenge/Week_1:_May_1st–May_7th/771_Jewels_and_Stones/solution.py -------------------------------------------------------------------------------- /Challenge/May_LeetCoding_Challenge/Week_2:_May_8th–May_14th/1232_Check_If_It_Is_a_Straight_Line/solution.py: -------------------------------------------------------------------------------- 1 | from typing import * 2 | 3 | 4 | class Solution: 5 | def checkStraightLine(self, coordinates: List[List[int]]) -> bool: 6 | (x0, y0), (x1, y1) = coordinates[:2] 7 | return all((x1 - x0) * (y - y1) == (x - x1) * (y1 - y0) for x, y in coordinates) 8 | -------------------------------------------------------------------------------- /Challenge/May_LeetCoding_Challenge/Week_2:_May_8th–May_14th/540_Single_Element_in_a_Sorted_Array/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func singleNonDuplicate(nums []int) int { 4 | sum := 0 5 | for i, num := range nums { 6 | if i%2 == 0 { 7 | sum += num 8 | } else { 9 | sum -= num 10 | } 11 | } 12 | return sum 13 | } 14 | -------------------------------------------------------------------------------- /Database/1050_Actors_and_Directors_Who_Cooperated_At_Least_Three_Times/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT actor_id, director_id 3 | FROM actordirector 4 | GROUP BY actor_id, director_id 5 | HAVING COUNT(1) >= 3 6 | ; 7 | -------------------------------------------------------------------------------- /Database/1084_Sales_Analysis_III/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT product_id, product_name 3 | FROM product 4 | WHERE product_id NOT IN ( 5 | SELECT product_id 6 | FROM sales 7 | WHERE 8 | SUBSTR(sale_date, 0, 10) < '2019-01-01' 9 | OR SUBSTR(sale_date, 0, 10) > '2019-03-31' 10 | ) 11 | ; 12 | -------------------------------------------------------------------------------- /Database/1141_User_Activity_for_the_Past_30_Days_I/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT 3 | SUBSTR(activity_date, 0, 10) day, 4 | COUNT(DISTINCT user_id) active_users 5 | FROM activity 6 | WHERE 7 | activity_date > TO_DATE('2019-07-27', 'YYYY-MM-DD') - 30 8 | AND activity_date < TO_DATE('2019-07-28', 'YYYY-MM-DD') 9 | GROUP BY activity_date 10 | ; 11 | -------------------------------------------------------------------------------- /Database/1148_Article_Views_I/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT DISTINCT author_id id 3 | FROM views 4 | WHERE author_id = viewer_id 5 | ORDER BY author_id 6 | ; 7 | -------------------------------------------------------------------------------- /Database/1350_Students_With_Invalid_Departments/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT a.id, a.name 3 | FROM students a 4 | LEFT OUTER JOIN departments b 5 | ON a.department_id = b.id 6 | WHERE b.id IS NULL 7 | ; 8 | -------------------------------------------------------------------------------- /Database/1355_Activity_Participants/solution.sql: -------------------------------------------------------------------------------- 1 | -- Oracle (pl/sql) 2 | WITH tmp AS ( 3 | SELECT activity, COUNT(1) cnt 4 | FROM friends 5 | GROUP BY activity 6 | ) 7 | SELECT activity 8 | FROM tmp 9 | WHERE (SELECT MIN(cnt) FROM tmp) < cnt 10 | AND cnt < (SELECT MAX(cnt) FROM tmp) 11 | ; 12 | -------------------------------------------------------------------------------- /Database/1393_Capita_ Gain_Loss/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT stock_name, SUM(price) capital_gain_loss 3 | FROM ( 4 | SELECT 5 | stock_name, 6 | CASE 7 | WHEN operation = 'Buy' THEN -price 8 | ELSE price 9 | END AS price 10 | FROM stocks 11 | ) a 12 | GROUP BY stock_name 13 | ; 14 | -------------------------------------------------------------------------------- /Database/1407_Top_Travellers/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT 3 | a.name, 4 | SUM( 5 | CASE 6 | WHEN b.distance IS NULL THEN 0 7 | ELSE b.distance 8 | END 9 | ) travelled_distance 10 | FROM users a 11 | LEFT JOIN rides b ON a.id = b.user_id 12 | GROUP BY a.id, a.name 13 | ORDER BY 14 | travelled_distance DESC, 15 | a.name ASC 16 | ; 17 | -------------------------------------------------------------------------------- /Database/1445_Apples_&_Oranges/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT 3 | SUBSTR(sale_date, 0, 10) sale_date, 4 | SUM(CASE fruit WHEN 'apples' THEN sold_num ELSE 0 END) - SUM(CASE fruit WHEN 'oranges' THEN sold_num ELSE 0 END) diff 5 | FROM sales 6 | GROUP BY sale_date 7 | ORDER BY sale_date 8 | ; 9 | -------------------------------------------------------------------------------- /Database/1484_Group_Sold_Products_By_The_Date/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT 3 | SUBSTR(sell_date, 0, 10) sell_date, 4 | COUNT(DISTINCT product) num_sold, LISTAGG(product, ',') WITHIN GROUP (ORDER BY product) products 5 | FROM ( 6 | SELECT DISTINCT sell_date, product 7 | FROM activities 8 | ) a 9 | GROUP BY sell_date 10 | ORDER BY sell_date 11 | ; 12 | -------------------------------------------------------------------------------- /Database/1527_Patients_With_a_Condition/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT 3 | patient_id, 4 | patient_name, 5 | conditions 6 | FROM patients 7 | WHERE 8 | conditions LIKE 'DIAB1%' 9 | OR conditions LIKE '% DIAB1%' 10 | ; 11 | -------------------------------------------------------------------------------- /Database/1581_Customer_Who_Visited_but_Did_Not_Make_Any_Transactions/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT 3 | a.customer_id, 4 | COUNT(1) count_no_trans 5 | FROM visits a 6 | LEFT JOIN transactions b ON a.visit_id = b.visit_id 7 | WHERE b.transaction_id IS NULL 8 | GROUP BY a.customer_id 9 | ; 10 | -------------------------------------------------------------------------------- /Database/1587_Bank_Account_Summary_II/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT name, balance 3 | FROM users a 4 | JOIN ( 5 | SELECT account, SUM(amount) balance 6 | FROM transactions 7 | GROUP BY account 8 | ) b 9 | ON a.account = b.account 10 | WHERE b.balance > 10000 11 | ; 12 | -------------------------------------------------------------------------------- /Database/1667_Fix_Names_in_a_Table/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT 3 | user_id, 4 | UPPER(SUBSTR(name, 0, 1)) || LOWER(SUBSTR(name, 2)) name 5 | FROM users 6 | ORDER BY user_id 7 | ; 8 | -------------------------------------------------------------------------------- /Database/1729_Find_Followers_Count/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT 3 | user_id, 4 | COUNT(follower_id) followers_count 5 | FROM followers 6 | GROUP BY user_id 7 | ORDER BY user_id 8 | ; 9 | -------------------------------------------------------------------------------- /Database/1741_Find_Total_Time_Spent_by_Each_Employee/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT 3 | SUBSTR(event_day, 0, 10) day, 4 | emp_id, 5 | SUM(out_time - in_time) total_time 6 | FROM employees 7 | GROUP BY event_day, emp_id 8 | ; 9 | -------------------------------------------------------------------------------- /Database/1757_Recyclable_and_Low_Fat_Products/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT product_id 3 | FROM products 4 | WHERE low_fats = 'Y' 5 | AND recyclable = 'Y' 6 | ; 7 | -------------------------------------------------------------------------------- /Database/175_Combine_Two_Tables/solution.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT FirstName, LastName, City, State 3 | FROM Person p 4 | LEFT JOIN Address a 5 | ON p.PersonId = a.PersonId 6 | ; 7 | -------------------------------------------------------------------------------- /Database/176_Second_Highest_Salary/solution.sql: -------------------------------------------------------------------------------- 1 | SELECT MAX(Salary) AS SecondHighestSalary 2 | FROM Employee 3 | WHERE Salary < (SELECT MAX(Salary) FROM Employee) 4 | ; 5 | -------------------------------------------------------------------------------- /Database/178_Rank_Scores/solution-mysql.sql: -------------------------------------------------------------------------------- 1 | SELECT a.Score, 2 | ( 3 | SELECT COUNT(DISTINCT b.Score) + 1 4 | FROM Scores b 5 | WHERE a.Score < b.Score 6 | ) Rank 7 | FROM Scores a 8 | ORDER BY a.Score DESC 9 | ; 10 | -------------------------------------------------------------------------------- /Database/178_Rank_Scores/solution-oracle.sql: -------------------------------------------------------------------------------- 1 | WITH Rank AS ( 2 | SELECT a.Score, row_number() over (ORDER BY Score DESC) Rank 3 | FROM ( 4 | SELECT DISTINCT ROUND(Score, 2) Score 5 | FROM Scores 6 | ORDER BY Score DESC 7 | ) a 8 | ) 9 | SELECT ROUND(a.Score, 2) Score, b.Rank 10 | FROM Scores a 11 | JOIN Rank b ON a.Score = b.Score 12 | ORDER BY b.Rank 13 | ; 14 | -------------------------------------------------------------------------------- /Database/1795_Rearrange_Products_Table/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT product_id, 'store1' store, store1 price FROM products WHERE store1 IS NOT NULL 3 | UNION 4 | SELECT product_id, 'store2' store, store2 price FROM products WHERE store2 IS NOT NULL 5 | UNION 6 | SELECT product_id, 'store3' store, store3 price FROM products WHERE store3 IS NOT NULL 7 | ; 8 | -------------------------------------------------------------------------------- /Database/180_Consecutive_Numbers/solution.sql: -------------------------------------------------------------------------------- 1 | -- OracleSQL 2 | SELECT DISTINCT(Num) ConsecutiveNums 3 | FROM ( 4 | SELECT Num, Id, ROW_NUMBER() OVER (PARTITION BY Num ORDER BY Id) row_num 5 | FROM Logs 6 | ) a 7 | GROUP BY Num, Id - row_num 8 | HAVING COUNT(1) > 2 9 | ; 10 | -------------------------------------------------------------------------------- /Database/181_Employees_Earning_More_Than_Their_Managers/solution.sql: -------------------------------------------------------------------------------- 1 | SELECT a.Name Employee 2 | FROM Employee a 3 | JOIN Employee b 4 | ON a.ManagerId = b.Id 5 | WHERE a.Salary > b.Salary 6 | ; 7 | -------------------------------------------------------------------------------- /Database/182_Duplicate_Emails/solution.sql: -------------------------------------------------------------------------------- 1 | -- OracleSQL 2 | SELECT Email 3 | FROM Person 4 | GROUP BY Email 5 | HAVING COUNT(1) > 1 6 | ; 7 | -------------------------------------------------------------------------------- /Database/183_Customers_Who_Never_Order/solution.sql: -------------------------------------------------------------------------------- 1 | -- OracleSQL 2 | SELECT Name Customers 3 | FROM Customers c 4 | LEFT JOIN Orders o 5 | ON c.Id = o.CustomerId 6 | WHERE o.CustomerId IS NULL 7 | ORDER BY c.Id 8 | ; 9 | -------------------------------------------------------------------------------- /Database/184_Department_Highest_Salary/solution.sql: -------------------------------------------------------------------------------- 1 | -- OracleSQL 2 | SELECT 3 | b.Name Department, 4 | a.Name Employee, 5 | a.Salary 6 | FROM Employee a 7 | JOIN ( 8 | SELECT d.*, ( 9 | SELECT DISTINCT(MAX(e.Salary) OVER (PARTITION BY d.Name ORDER BY e.Salary DESC)) Salary 10 | FROM Employee e 11 | WHERE d.Id = e.DepartmentId 12 | ) Salary 13 | FROM Department d 14 | ) b 15 | ON ( 16 | a.DepartmentId = b.Id AND 17 | a.Salary = b.Salary 18 | ) 19 | ORDER BY a.Salary DESC 20 | ; 21 | -------------------------------------------------------------------------------- /Database/185_Department_Top_Three_Salaries/solution.sql: -------------------------------------------------------------------------------- 1 | -- OracleSQL 2 | SELECT 3 | Department, 4 | Employee, 5 | Salary 6 | FROM ( 7 | SELECT 8 | d.Name Department, 9 | e.Name Employee, 10 | e.Salary Salary, 11 | DENSE_RANK() OVER (PARTITION BY d.Id ORDER BY e.Salary DESC) row_num 12 | FROM Employee e 13 | JOIN Department d 14 | ON d.Id = e.DepartmentId 15 | ) a 16 | WHERE row_num < 4 17 | ; 18 | -------------------------------------------------------------------------------- /Database/1873_Calculate_Special_Bonus/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT employee_id, salary bonus 3 | FROM ( 4 | SELECT employee_id, salary 5 | FROM employees 6 | WHERE MOD(employee_id, 2) = 1 AND SUBSTR(name, 0, 1) != 'M' 7 | UNION 8 | SELECT employee_id, 0 9 | FROM employees 10 | WHERE MOD(employee_id, 2) = 0 OR SUBSTR(name, 0, 1) = 'M' 11 | ) 12 | ORDER BY employee_id 13 | ; 14 | -------------------------------------------------------------------------------- /Database/1890_The_Latest_Login_in_2020/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT 3 | user_id, 4 | MAX(time_stamp) last_stamp 5 | FROM logins 6 | GROUP BY 7 | user_id, 8 | SUBSTR(time_stamp, 0, 4) 9 | HAVING SUBSTR(time_stamp, 0, 4) = '2020' 10 | ; 11 | -------------------------------------------------------------------------------- /Database/1965_Employees_With_Missing_Information/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT employee_id 3 | FROM ( 4 | SELECT 5 | NVL(a.employee_id, b.employee_id) employee_id 6 | FROM employees a 7 | FULL OUTER JOIN salaries b ON a.employee_id = b.employee_id 8 | WHERE a.name IS NULL OR b.salary IS NULL 9 | ) a 10 | ORDER BY employee_id 11 | ; 12 | -------------------------------------------------------------------------------- /Database/197_Rising_Temperature/solution.sql: -------------------------------------------------------------------------------- 1 | -- OracleSQL 2 | SELECT a.Id 3 | FROM 4 | Weather a, 5 | Weather b 6 | WHERE 7 | a.RecordDate - b.RecordDate = 1 AND 8 | a.Temperature > b.Temperature 9 | ORDER BY a.Id 10 | ; 11 | -------------------------------------------------------------------------------- /Database/511_Game_Play_Analysis_I/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT player_id, MIN(TO_CHAR(event_date, 'YYYY-MM-DD')) first_login 3 | FROM activity 4 | GROUP BY player_id 5 | ; 6 | -------------------------------------------------------------------------------- /Database/584_Find_Customer_Referee/solution.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT name 3 | FROM customer 4 | WHERE referee_id IS NULL OR referee_id != 2 5 | ; 6 | -------------------------------------------------------------------------------- /Database/586_Customer_Placing_the_Largest_Number_of_Orders/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | WITH tmp AS ( 3 | SELECT customer_number, COUNT(customer_number) cnt 4 | FROM orders 5 | GROUP BY customer_number 6 | ORDER BY cnt DESC 7 | ) 8 | SELECT a.customer_number 9 | FROM ( 10 | SELECT customer_number, cnt 11 | FROM tmp 12 | WHERE rownum = 1 13 | ) a, tmp b 14 | WHERE a.cnt = b.cnt 15 | ; 16 | -------------------------------------------------------------------------------- /Database/595_Big_Countries/solution.sql: -------------------------------------------------------------------------------- 1 | -- OracleSQL 2 | SELECT name, population, area 3 | FROM World 4 | WHERE area >= 3000000 OR population >= 25000000; 5 | -------------------------------------------------------------------------------- /Database/596_Classes_More_Than_5_Students/solution.sql: -------------------------------------------------------------------------------- 1 | -- Oracle 2 | SELECT class 3 | FROM courses 4 | GROUP BY class 5 | HAVING COUNT(DISTINCT(student)) > 4 6 | ; 7 | -------------------------------------------------------------------------------- /Database/601_Human_Traffic_of_Stadium/solution.sql: -------------------------------------------------------------------------------- 1 | -- OracleSQL 2 | SELECT DISTINCT a.id, TO_CHAR(a.visit_date, 'YYYY-MM-DD') visit_date, a.people 3 | FROM stadium a, stadium b, stadium c 4 | WHERE ( 5 | (a.people > 99 AND b.people > 99 AND c.people > 99) AND 6 | ( 7 | (a.id + 1 = b.id AND a.id + 2 = c.id) OR 8 | (a.id - 1 = b.id AND a.id + 1 = c.id) OR 9 | (a.id - 2 = b.id AND a.id - 1 = c.id) 10 | ) 11 | ) 12 | ORDER BY a.id 13 | ; 14 | -------------------------------------------------------------------------------- /Database/607_Sales_Person/solution.sql: -------------------------------------------------------------------------------- 1 | /* Write your PL/SQL query statement below */ 2 | SELECT name 3 | FROM salesperson 4 | WHERE sales_id NOT IN ( 5 | SELECT sales_id 6 | FROM orders a 7 | JOIN (SELECT com_id FROM company WHERE name = 'RED') b 8 | ON a.com_id = b.com_id 9 | ) 10 | ; 11 | -------------------------------------------------------------------------------- /Database/620_Not_Boring_Movies/solution.sql: -------------------------------------------------------------------------------- 1 | -- OracleSQL 2 | SELECT * 3 | FROM cinema 4 | WHERE 5 | MOD(id, 2) = 1 AND 6 | description != 'boring' 7 | ORDER BY rating DESC 8 | ; 9 | -------------------------------------------------------------------------------- /Database/626_Exchange_Seats/solution.sql: -------------------------------------------------------------------------------- 1 | -- OracleSQL 2 | SELECT 3 | ROW_NUMBER() OVER (ORDER BY id) id, 4 | student 5 | FROM ( 6 | SELECT 7 | CASE 8 | WHEN (MOD(id, 2) = 0) THEN id - 1 9 | ELSE id + 1 10 | END AS id, 11 | student 12 | FROM seat 13 | ) a 14 | ORDER BY id 15 | ; 16 | -------------------------------------------------------------------------------- /Database/627_Swap_Salary/solution.sql: -------------------------------------------------------------------------------- 1 | -- OracleSQL 2 | UPDATE salary 3 | SET sex = CASE WHEN (sex = 'm') THEN 'f' ELSE 'm' END 4 | ; 5 | -------------------------------------------------------------------------------- /Shell/192_Word_Frequency/solution.sh: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/bash 2 | 3 | # Make sure bash version over 4 4 | 5 | declare -A WORD_COUNT 6 | ARR=(`cat words.txt | tr ' ' '\n'`) 7 | 8 | for WORD in "${ARR[@]}" 9 | do 10 | WORD_COUNT["${WORD}"]=$((WORD_COUNT["${WORD}"] + 1)) 11 | done 12 | 13 | for key in "${!WORD_COUNT[@]}" 14 | do 15 | echo "$key ${WORD_COUNT[$key]}" 16 | done | 17 | sort -rn -k2 18 | -------------------------------------------------------------------------------- /Shell/193_Valid_Phone_Numbers/solution.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | grep -P "^(\(\\d{3}\) |\\d{3}-)\\d{3}-\\d{4}$" file.txt 3 | -------------------------------------------------------------------------------- /Shell/194_Transpose_File/solution.sh: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/bash 2 | awk ' 3 | { 4 | for (i = 1; i <= NF; i++) { 5 | if (NR == 1) { 6 | s[i] = $i; 7 | } else { 8 | s[i] = s[i] " " $i 9 | } 10 | } 11 | } 12 | END { 13 | for (i = 1; s[i] != ""; i++) { 14 | print s[i]; 15 | } 16 | }' file.txt 17 | -------------------------------------------------------------------------------- /Shell/195_Tenth_Line/solution.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if ((`head -n 10 file.txt | wc -l` < 10)); then 3 | echo '' 4 | else 5 | head -n 10 file.txt | tail -n 1 6 | fi 7 | -------------------------------------------------------------------------------- /analysis/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/__init__.py -------------------------------------------------------------------------------- /analysis/job/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/job/__init__.py -------------------------------------------------------------------------------- /analysis/job/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/job/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /analysis/job/__pycache__/job.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/job/__pycache__/job.cpython-310.pyc -------------------------------------------------------------------------------- /analysis/job/job.py: -------------------------------------------------------------------------------- 1 | from abc import ABCMeta, abstractmethod 2 | 3 | 4 | class Job: 5 | __metaclass__ = ABCMeta 6 | 7 | @abstractmethod 8 | def run(self): 9 | raise NotImplementedError 10 | -------------------------------------------------------------------------------- /analysis/logger/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/logger/__init__.py -------------------------------------------------------------------------------- /analysis/logger/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/logger/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /analysis/logger/__pycache__/logger.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/logger/__pycache__/logger.cpython-310.pyc -------------------------------------------------------------------------------- /analysis/logger/logger.py: -------------------------------------------------------------------------------- 1 | from analysis.util.dateutils import get_kst_now 2 | 3 | 4 | def info(msg: str) -> None: 5 | __log('INFO', msg) 6 | 7 | 8 | def warn(msg: str) -> None: 9 | __log('WARN', msg) 10 | 11 | 12 | def error(msg: str) -> None: 13 | __log('ERROR', msg) 14 | 15 | 16 | def __log(level: str, msg: str) -> None: 17 | print(f'[{get_kst_now()}] {level} {msg}') 18 | -------------------------------------------------------------------------------- /analysis/output/language_statistics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/output/language_statistics.png -------------------------------------------------------------------------------- /analysis/output/ranking_graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/output/ranking_graph.png -------------------------------------------------------------------------------- /analysis/service/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/service/__init__.py -------------------------------------------------------------------------------- /analysis/service/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/service/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /analysis/service/__pycache__/github.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/service/__pycache__/github.cpython-310.pyc -------------------------------------------------------------------------------- /analysis/service/__pycache__/leetcode.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/service/__pycache__/leetcode.cpython-310.pyc -------------------------------------------------------------------------------- /analysis/service/__pycache__/line.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/service/__pycache__/line.cpython-310.pyc -------------------------------------------------------------------------------- /analysis/util/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/util/__init__.py -------------------------------------------------------------------------------- /analysis/util/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/util/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /analysis/util/__pycache__/dateutils.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/util/__pycache__/dateutils.cpython-310.pyc -------------------------------------------------------------------------------- /analysis/util/__pycache__/encodingutils.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/util/__pycache__/encodingutils.cpython-310.pyc -------------------------------------------------------------------------------- /analysis/util/dateutils.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime, timedelta 2 | 3 | DEFAULT_FORMAT = '%Y-%m-%d %H:%M:%S' 4 | 5 | 6 | def get_epoch_ms(dt: datetime = datetime.now()) -> int: 7 | return int(dt.timestamp() * 1000) 8 | 9 | 10 | def epoch_ms_to_date_str(epoch_ms: int, fmt: str = DEFAULT_FORMAT) -> str: 11 | return datetime.fromtimestamp(epoch_ms / 1000).strftime(fmt) 12 | 13 | 14 | def get_kst_now(fmt: str = DEFAULT_FORMAT) -> str: 15 | return (datetime.utcnow() + timedelta(hours=9)).strftime(fmt) 16 | -------------------------------------------------------------------------------- /analysis/util/encodingutils.py: -------------------------------------------------------------------------------- 1 | import base64 2 | 3 | 4 | def encode_binary_to_base64(file_path: str) -> bytes: 5 | with open(file_path, 'rb') as file: 6 | return base64.b64encode(file.read()) 7 | -------------------------------------------------------------------------------- /analysis/vo/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/vo/__init__.py -------------------------------------------------------------------------------- /analysis/vo/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/vo/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /analysis/vo/__pycache__/emoji.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/vo/__pycache__/emoji.cpython-310.pyc -------------------------------------------------------------------------------- /analysis/vo/__pycache__/message.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/occidere/leetcode/f896272a87cbc50110929e4cd30ab8d331665fd6/analysis/vo/__pycache__/message.cpython-310.pyc -------------------------------------------------------------------------------- /analysis/vo/emoji.py: -------------------------------------------------------------------------------- 1 | class Emoji: 2 | """ 3 | https://developers.line.biz/en/docs/messaging-api/emoji-list/#line-emoji-definitions 4 | """ 5 | 6 | def __init__(self, index: int, product_id: str, emoji_id: str) -> None: 7 | self.index, self.product_id, self.emoji_id = index, product_id, emoji_id 8 | --------------------------------------------------------------------------------