Skip to content

Commit

Permalink
separate problems and answers
Browse files Browse the repository at this point in the history
  • Loading branch information
alisenola committed Feb 2, 2020
1 parent 71f25c2 commit 7f2d6cd
Show file tree
Hide file tree
Showing 243 changed files with 299 additions and 296 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
target/
.idea/
File renamed without changes.
239 changes: 2 additions & 237 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,240 +1,5 @@
#[macro_use]
pub mod util;

mod n0006_zigzag_conversion;
mod n0238_product_of_array_except_self;
mod n0115_distinct_subsequences;
mod n0099_recover_binary_search_tree;
mod n0310_minimum_height_trees;
mod n0128_longest_consecutive_sequence;
mod n0274_h_index;
mod n0241_different_ways_to_add_parentheses;
mod n0024_swap_nodes_in_pairs;
mod n0110_balanced_binary_tree;
mod n0093_restore_ip_addresses;
mod n0076_minimum_window_substring;
mod n0124_binary_tree_maximum_path_sum;
mod n0122_best_time_to_buy_and_sell_stock_ii;
mod n0169_majority_element;
mod n0162_find_peak_element;
mod n0095_unique_binary_search_trees_ii;
mod n0155_min_stack;
mod n0040_combination_sum_ii;
mod n0217_contains_duplicate;
mod n0055_jump_game;
mod n0106_construct_binary_tree_from_inorder_and_postorder_traversal;
mod n0145_binary_tree_postorder_traversal;
mod n0079_word_search;
mod n0969_pancake_sorting;
mod n0042_trapping_rain_water;
mod n0108_convert_sorted_array_to_binary_search_tree;
mod n0083_remove_duplicates_from_sorted_list;
mod n0130_surrounded_regions;
mod n0226_invert_binary_tree;
mod n0027_remove_element;
mod n0188_best_time_to_buy_and_sell_stock_iv;
mod n0204_count_primes;
mod n0268_missing_number;
mod n0214_shortest_palindrome;
mod n0231_power_of_two;
mod n0202_happy_number;
mod n0075_sort_colors;
mod n0066_plus_one;
mod n0028_implement_strstr;
mod n0290_word_pattern;
mod n0048_rotate_image;
mod n0089_gray_code;
mod n0147_insertion_sort_list;
mod n0084_largest_rectangle_in_histogram;
mod n0011_container_with_most_water;
mod n0009_palindrome_number;
mod n0058_length_of_last_word;
mod n0080_remove_duplicates_from_sorted_array_ii;
mod n0030_substring_with_concatenation_of_all_words;
mod n0060_permutation_sequence;
mod n0071_simplify_path;
mod n0038_count_and_say;
mod n0144_binary_tree_preorder_traversal;
mod n0279_perfect_squares;
mod n0304_range_sum_query_2d_immutable;
mod n0292_nim_game;
mod n0264_ugly_number_ii;
mod n0132_palindrome_partitioning_ii;
mod n0019_remove_nth_node_from_end_of_list;
mod n0136_single_number;
mod n0018_4sum;
mod n0220_contains_duplicate_iii;
mod n0299_bulls_and_cows;
mod n0232_implement_queue_using_stacks;
mod n0100_same_tree;
mod n0171_excel_sheet_column_number;
mod n0087_scramble_string;
mod n0704_binary_search;
mod n0219_contains_duplicate_ii;
mod n0086_partition_list;
mod n0082_remove_duplicates_from_sorted_list_ii;
mod n0228_summary_ranges;
mod n0020_valid_parentheses;
mod n0017_letter_combinations_of_a_phone_number;
mod n0312_burst_balloons;
mod n0306_additive_number;
mod n0283_move_zeroes;
mod n1018_binary_prefix_divisible_by_5;
mod n0201_bitwise_and_of_numbers_range;
mod n0109_convert_sorted_list_to_binary_search_tree;
mod n0101_symmetric_tree;
mod n0098_validate_binary_search_tree;
mod n0035_search_insert_position;
mod n0050_powx_n;
mod n0198_house_robber;
mod n0004_median_of_two_sorted_arrays;
mod n0221_maximal_square;
mod n0047_permutations_ii;
mod n0172_factorial_trailing_zeroes;
mod n0054_spiral_matrix;
mod n0053_maximum_subarray;
mod n1046_last_stone_weight;
mod n0146_lru_cache;
mod n0126_word_ladder_ii;
mod n0242_valid_anagram;
mod n0112_path_sum;
mod n0023_merge_k_sorted_lists;
mod n0230_kth_smallest_element_in_a_bst;
mod n0104_maximum_depth_of_binary_tree;
mod n0258_add_digits;
mod n0187_repeated_dna_sequences;
mod n0025_reverse_nodes_in_k_group;
mod n0039_combination_sum;
mod n0107_binary_tree_level_order_traversal_ii;
mod n0091_decode_ways;
mod n0056_merge_intervals;
mod n0065_valid_number;
mod n0016_3sum_closest;
mod n0096_unique_binary_search_trees;
mod n0072_edit_distance;
mod n0044_wildcard_matching;
mod n0239_sliding_window_maximum;
mod n0174_dungeon_game;
mod n0073_set_matrix_zeroes;
mod n0078_subsets;
mod n0037_sudoku_solver;
mod n0033_search_in_rotated_sorted_array;
mod n0002_add_two_numbers;
mod n0313_super_ugly_number;
mod n0068_text_justification;
mod n0064_minimum_path_sum;
mod n0218_the_skyline_problem;
mod n0125_valid_palindrome;
mod n0210_course_schedule_ii;
mod n0143_reorder_list;
mod n0164_maximum_gap;
mod n0097_interleaving_string;
mod n0105_construct_binary_tree_from_preorder_and_inorder_traversal;
mod n0167_two_sum_ii_input_array_is_sorted;
mod n0034_find_first_and_last_position_of_element_in_sorted_array;
mod n0094_binary_tree_inorder_traversal;
mod n0052_n_queens_ii;
mod n0121_best_time_to_buy_and_sell_stock;
mod n0273_integer_to_english_words;
mod n0225_implement_stack_using_queues;
mod n0046_permutations;
mod n0085_maximal_rectangle;
mod n0135_candy;
mod n0113_path_sum_ii;
mod n0029_divide_two_integers;
mod n0260_single_number_iii;
mod n0140_word_break_ii;
mod n0149_max_points_on_a_line;
mod n0213_house_robber_ii;
mod n0222_count_complete_tree_nodes;
mod n0134_gas_station;
mod n0057_insert_interval;
mod n0173_binary_search_tree_iterator;
mod n0077_combinations;
mod n0005_longest_palindromic_substring;
mod n0041_first_missing_positive;
mod n0026_remove_duplicates_from_sorted_array;
mod n0166_fraction_to_recurring_decimal;
mod n0119_pascals_triangle_ii;
mod n0012_integer_to_roman;
mod n0223_rectangle_area;
mod n0229_majority_element_ii;
mod n0061_rotate_list;
mod n0123_best_time_to_buy_and_sell_stock_iii;
mod n0301_remove_invalid_parentheses;
mod n0067_add_binary;
mod n0049_group_anagrams;
mod n0189_rotate_array;
mod n0001_two_sum;
mod n0275_h_index_ii;
mod n0103_binary_tree_zigzag_level_order_traversal;
mod n0137_single_number_ii;
mod n0208_implement_trie_prefix_tree;
mod n0300_longest_increasing_subsequence;
mod n0118_pascals_triangle;
mod n0010_regular_expression_matching;
mod n0013_roman_to_integer;
mod n0209_minimum_size_subarray_sum;
mod n0227_basic_calculator_ii;
mod n0022_generate_parentheses;
mod n0008_string_to_integer_atoi;
mod n0152_maximum_product_subarray;
mod n0014_longest_common_prefix;
mod n0070_climbing_stairs;
mod n0233_number_of_digit_one;
mod n0154_find_minimum_in_rotated_sorted_array_ii;
mod n0127_word_ladder;
mod n0207_course_schedule;
mod n0263_ugly_number;
mod n0295_find_median_from_data_stream;
mod n0148_sort_list;
mod n0257_binary_tree_paths;
mod n0120_triangle;
mod n0309_best_time_to_buy_and_sell_stock_with_cooldown;
mod n0074_search_a_2d_matrix;
mod n0215_kth_largest_element_in_an_array;
mod n0203_remove_linked_list_elements;
mod n0081_search_in_rotated_sorted_array_ii;
mod n0059_spiral_matrix_ii;
mod n0151_reverse_words_in_a_string;
mod n0205_isomorphic_strings;
mod n0179_largest_number;
mod n0168_excel_sheet_column_title;
mod n0007_reverse_integer;
mod n0032_longest_valid_parentheses;
mod n0165_compare_version_numbers;
mod n0031_next_permutation;
mod n0088_merge_sorted_array;
mod n0509_fibonacci_number;
mod n0036_valid_sudoku;
mod n0069_sqrtx;
mod n0211_add_and_search_word_data_structure_design;
mod n0114_flatten_binary_tree_to_linked_list;
mod n0224_basic_calculator;
mod n0045_jump_game_ii;
mod n0051_n_queens;
mod n0212_word_search_ii;
mod n0287_find_the_duplicate_number;
mod n0153_find_minimum_in_rotated_sorted_array;
mod n0289_game_of_life;
mod n0200_number_of_islands;
mod n0015_3sum;
mod n0216_combination_sum_iii;
mod n0043_multiply_strings;
mod n0090_subsets_ii;
mod n0003_longest_substring;
mod n0139_word_break;
mod n0150_evaluate_reverse_polish_notation;
mod n0063_unique_paths_ii;
mod n0062_unique_paths;
mod n0199_binary_tree_right_side_view;
mod n0282_expression_add_operators;
mod n0021_merge_two_sorted_lists;
mod n0129_sum_root_to_leaf_numbers;
mod n0206_reverse_linked_list;
mod n0131_palindrome_partitioning;
mod n0307_range_sum_query_mutable;
mod n0111_minimum_depth_of_binary_tree;
mod n0092_reverse_linked_list_ii;
mod n0303_range_sum_query_immutable;
mod n0102_binary_tree_level_order_traversal;
pub mod solution;
pub mod problem;
16 changes: 8 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate serde_derive;
#[macro_use]
extern crate serde_json;

mod problem;
mod fetcher;

use std::env;
use std::fs;
Expand Down Expand Up @@ -45,7 +45,7 @@ fn main() {
}
}

let problem = problem::get_problem(id).unwrap_or_else(|| {
let problem = fetcher::get_problem(id).unwrap_or_else(|| {
panic!(
"Error: failed to get problem #{} \
(The problem may be paid-only or may not be exist).",
Expand All @@ -61,11 +61,11 @@ fn main() {
let code = code.unwrap();

let file_name = format!(
"n{:04}_{}",
"p{:04}_{}",
problem.question_id,
problem.title_slug.replace("-", "_")
);
let file_path = Path::new("./src").join(format!("{}.rs", file_name));
let file_path = Path::new("./src/problem").join(format!("{}.rs", file_name));
if file_path.exists() {
panic!("problem already initialized");
}
Expand All @@ -91,7 +91,7 @@ fn main() {
let mut lib_file = fs::OpenOptions::new()
.write(true)
.append(true)
.open("./src/lib.rs")
.open("./src/problem/mod.rs")
.unwrap();
writeln!(lib_file, "mod {};", file_name);
break;
Expand Down Expand Up @@ -136,13 +136,13 @@ fn parse_extra_use(code: &str) -> String {
let mut extra_use_line = String::new();
// a linked-list problem
if code.contains("pub struct ListNode") {
extra_use_line.push_str("\nuse super::util::linked_list::{ListNode, to_list};")
extra_use_line.push_str("\nuse crate::util::linked_list::{ListNode, to_list};")
}
if code.contains("pub struct TreeNode") {
extra_use_line.push_str("\nuse super::util::tree::{TreeNode, to_tree};")
extra_use_line.push_str("\nuse crate::util::tree::{TreeNode, to_tree};")
}
if code.contains("pub struct Point") {
extra_use_line.push_str("\nuse super::util::point::Point;")
extra_use_line.push_str("\nuse crate::util::point::Point;")
}
extra_use_line
}
Expand Down
Empty file added src/problem/mod.rs
Empty file.
Loading

0 comments on commit 7f2d6cd

Please sign in to comment.