CodingTour
ARTS #177

Algorithm

本周选择的算法题是:Set Mismatch

规则

You have a set of integers s, which originally contains all the numbers from 1 to n. Unfortunately, due to some error, one of the numbers in s got duplicated to another number in the set, which results in repetition of one number and loss of another number.

You are given an integer array nums representing the data status of this set after the error.

Find the number that occurs twice and the number that is missing and return them in the form of an array.

Example 1:

Input: nums = [1,2,2,4]
Output: [2,3]

Example 2:

Input: nums = [1,1]
Output: [1,2]

Constraints:

  • 2 <= nums.length <= 104
  • 1 <= nums[i] <= 104

Solution

impl Solution {
    pub fn find_error_nums(mut nums: Vec<i32>) -> Vec<i32> {
        let mut dup = -1;
        for i in 0..nums.len() {
            let index = nums[i].abs()-1;
            if nums[index as usize] < 0 { 
                dup = nums[i].abs();
            } else {
                nums[index as usize] = nums[index as usize] * -1;
            }
        }
        let mut missing = -1;
        for i in 0..nums.len() {
            if nums[i] > 0 {
                missing = (i+1) as i32;
                break;
            }
        }
        vec![dup, missing]
    }
}

Review

Photoshop for text

最近 AI 创作话题很火,当大家把注意力放在视频、图片载体上时,这篇文章的作者却注意到了文字这个“古老的”内容载体。

也许未来会出现基于文本生成器创作的文章,或者更专业的内容,如800字作文、低重复率的论文,甚至是小说等等,从技术角度来说应该不是什么难度,美国国会图书馆 有1亿4700万图书,用来作为训练 AI 的样本应该绰绰有余了。

但也有可能完全跳过文字,直接面向下一代内容载体,毕竟内容载体的演进趋势是往更丰富的交互方向前进。

Tip

一个有意思的 “浏览器”:Arc

Share

分享一篇 “旧文”:新商业逻辑:离场者补贴坚持者

我们的生活中已经大量充斥着类似的情况,以文中健身房来说:

对于健身会所来说,如果每个会员每天都去健身,那么它的场地、设施和服务人员都是不够的,但总有去的多的和去的少的,去的少的也无形中补贴了去的多的。

健身卡之所以便宜,是因为大多数人坚持不了,所以它的购买成本才能如此之低。

除了用户视角,企业视角也同理。十年前的 “千团大战” 中,虽然最后活下来的是美团,但打市场、培养用户习惯的那些竞争者,却是用真金白银扩大市场规模,等到他们退出竞争后,市场规模并不会随之缩小,释放出的资源就留给了坚持下来的企业,当年 Google 退出中国也是类似的结局。