~statianzo/cracking

aaabec05a8107243f68b187eb5e239148a9154be — Jason Staten 3 years ago 3c99f1b
format docs
2 files changed, 11 insertions(+), 5 deletions(-)

M src/cc01_3.rs
M src/cc17_1.rs
M src/cc01_3.rs => src/cc01_3.rs +10 -4
@@ 1,18 1,24 @@
//! # Cracking the Coding Interview 1.3
//! # Problem
//! ## Problem
//! **URLify:** Write a method to replace all spaces in a string with `%20`: You may
//! assume that the string has sufficient space at the end to hold the additional
//! characters, and that you are given the "true" length of the string. (Note: if
//! implementing in Java, please use a character array so that you can perform
//! this operation in place.)
//! EXAMPLE
//! Input: "Mr John Smith   ", 13
//! Output: "Mr%20John%20Smith"
//!
//! ```
//! # use cracking::cc01_3::urlify;
//! let input = "Mr John Smith";
//! let output = urlify(input);
//! assert_eq!(output, "Mr%20John%20Smith")
//! ```

/// Replace " " with "%20"
pub fn urlify(input: &str) -> String {
    input.replace(" ", "%20")
}

/// Replace " " with "%20". Edits in place
pub fn urlify_inplace(input: &mut [u8], true_length: usize) {
    let mut insert_at = input.len() - 1;
    for i in (0..true_length).rev() {

M src/cc17_1.rs => src/cc17_1.rs +1 -1
@@ 1,5 1,5 @@
//! # Cracking the Coding Interview 17.1
//! # Problem
//! ## Problem
//! **Add Without Plus:** Write a function that adds two numbers. You should not
//! use + or any arithmetic operators
//!