Contents

ARST打卡第322周

Algorithm

lc1865_找出和为指定值的下标对

思路:

看数据范围就能知道需要遍历nums1, 然后去nums2的 count map 计数中去进行查找。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use std::collections::HashMap;
struct FindSumPairs {
    nums1: Vec<i32>,
    nums2: Vec<i32>,
    nums2_count: HashMap<i32, i32>,
}


/** 
 * `&self` means the method takes an immutable reference.
 * If you need a mutable reference, change it to `&mut self` instead.
 */
impl FindSumPairs {

    fn new(nums1: Vec<i32>, nums2: Vec<i32>) -> Self {
        let mut nums2_count = HashMap::new();
        for num in nums2.iter() {
            *nums2_count.entry(*num).or_insert(0) += 1;
        }
        Self {
            nums1,
            nums2,
            nums2_count,
        }
    }
    
    fn add(&mut self, index: i32, val: i32) {
        self.nums2[index as usize] += val;
        *self.nums2_count.entry(self.nums2[index as usize]).or_insert(0) += 1;
        *self.nums2_count.entry(self.nums2[index as usize] - val).or_insert(0) -= 1;
    }
    
    fn count(&self, tot: i32) -> i32 {
        let mut count = 0;
        for num in &self.nums1 {
            count += self.nums2_count.get(&(tot - num)).unwrap_or(&0);
        }
        count
    }
}

/**
 * Your FindSumPairs object will be instantiated and called as such:
 * let obj = FindSumPairs::new(nums1, nums2);
 * obj.add(index, val);
 * let ret_2: i32 = obj.count(tot);
 */

Review

【TED演讲】无人驾驶汽车如何看路

讲的是激光雷达训练,但是很多自动驾驶现在全用图像识别了。

Tips

Claude Code 实际如何使用的一些经验分享

其实 cursor 设置里面也有一个 auto run 的开关,开启之后就能自动运行而不用反复确认点击了。

Share

SNS介绍