We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The solution with swap instead shift passes all tests and optimize this case. So I keep it and go forward.
usestd::io;fnmain(){letreader=io::stdin();letmutinput=String::new();reader.read_line(&mutinput).expect("fail to readline");letsize=input.trim().parse::<usize>().expect("not a number");letmutvalues=Vec::with_capacity(size);letmutcount=0;input.clear();reader.read_line(&mutinput).expect("fail to readline");forvalueininput.split_whitespace(){values.push(value.parse::<i32>().expect("not a number"));}foriin1..values.len(){forjin0..i{ifvalues[i]<values[j]{lettmp=values[i];values[i]=values[j];values[j]=tmp;count+=1;}}}println!("{}",count);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Running Time of Algorithms
You are viewing a single comment's thread. Return to all comments →
The solution with swap instead shift passes all tests and optimize this case. So I keep it and go forward.