File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -373,6 +373,7 @@ mod q778;
373373mod q781;
374374mod q783;
375375mod q784;
376+ mod q786;
376377mod q788;
377378mod q789;
378379mod q796;
Original file line number Diff line number Diff line change 1+ use crate :: q:: Solution ;
2+
3+ #[ allow( unused) ]
4+ impl Solution {
5+ pub fn kth_smallest_prime_fraction ( arr : Vec < i32 > , k : i32 ) -> Vec < i32 > {
6+ // 方法1
7+ // 看到数据量不大,就尝试暴力一下,结果直接AC了,赶时间,先Mark,后面再来看有什么其他方法优化
8+ // AC 188ms 19.3mb 59/59
9+ let n = arr. len ( ) ;
10+ let mut ans = Vec :: new ( ) ;
11+ for i in 0 ..n {
12+ for j in i + 1 ..n {
13+ ans. push ( ( arr[ i] as f64 / arr[ j] as f64 , i, j) ) ;
14+ }
15+ }
16+ ans. sort_unstable_by ( |a, b| a. 0 . partial_cmp ( & b. 0 ) . unwrap ( ) ) ;
17+ vec ! [ arr[ ans[ k as usize - 1 ] . 1 ] , arr[ ans[ k as usize - 1 ] . 2 ] ]
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments