You are viewing a single comment's thread. Return to all comments →
RUST:
fn biggerIsGreater(w: &str) -> String { let length = w.len(); let mut temp = w.chars().collect::<Vec<char>>(); let mut i = None; // let mut idx: Option<usize> = None; let mut smallest = 'z'; for a in (0..length - 1).rev() { if temp[a] < temp[a + 1] { i = Some(a); break; } } if let Some(i) = i { let mut j = i + 1; for k in i + 1..length { if temp[k] > temp[i] && (j == i + 1 || temp[k] < temp[j]) { idx = Some(k); } } if let Some(j) = idx { temp.swap(i, j); temp[i + 1..].sort(); } temp.iter().collect() } else { "no answer".into() } }
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Bigger is Greater
You are viewing a single comment's thread. Return to all comments →
RUST: