CodingTour
ARTS #186 | 阳康了

Algorithm

本周选择的算法题是:Maximum Ice Cream Bars

规则

It is a sweltering summer day, and a boy wants to buy some ice cream bars.

At the store, there are n ice cream bars. You are given an array costs of length n, where costs[i] is the price of the ith ice cream bar in coins. The boy initially has coins coins to spend, and he wants to buy as many ice cream bars as possible.

Return the maximum number of ice cream bars the boy can buy with coins coins.

Note: The boy can buy the ice cream bars in any order.

Example 1:

Input: costs = [1,3,2,4,1], coins = 7
Output: 4
Explanation: The boy can buy ice cream bars at indices 0,1,2,4 for a total price of 1 + 3 + 2 + 1 = 7.

Example 2:

Input: costs = [10,6,8,7,7,8], coins = 5
Output: 0
Explanation: The boy cannot afford any of the ice cream bars.

Example 3:

Input: costs = [1,6,3,1,2,5], coins = 20
Output: 6
Explanation: The boy can buy all the ice cream bars for a total price of 1 + 6 + 3 + 1 + 2 + 5 = 18.

Constraints:

  • costs.length == n
  • 1 <= n <= 105
  • 1 <= costs[i] <= 105
  • 1 <= coins <= 108

Solution

impl Solution {
    pub fn max_ice_cream(mut costs: Vec<i32>, coins: i32) -> i32 {
        costs.sort_unstable();
        let mut sum = 0;
        for i in 0..costs.len(){
            if sum + costs[i] > coins {
                return i as i32;
            }
            sum += costs[i];
        }
        costs.len() as i32
    }
}

Review

Databases in 2022: A Year in Review

作者总结了数据库过去的一年,有挺多引人深思的观点,比如到 2025 年,50% 的独立 DBMS 供应商将倒闭,还有对 Blockchain Database 的看法等。总的来说不太乐观,这其中有整体科技行业降温的大趋势,包括对通货膨胀、利率和加密经济崩溃的担忧等,另一方面,在早前两年,有能力进行大额融资的公司都已经完成了融资,如 Starburst 在 2021 年进行了 1 亿美元的 C 轮融资后于 2022 年进行了 D 轮融资,行业在过去两年消耗的资金总额相当惊人,未来不可持续也在情理当中。

值得一读~

Tip

HTTP Status Dogs 每个 HTTP 状态码对应了一只狗的图片,喜欢猫?也有: HTTP Status Cats

Share

分析一下站酷和小红书的移动端 App 架构~

站酷采用了 React Native + 原生渲染的方式:

  • 站酷的业务逻辑主要是用 RN 实现
  • 因为 RN 的原因,交互组件采用了纯原生渲染,如下拉刷新组件 MJRefresh、相册组件 TZImagePickerController、吐司组件 ProgressHUD 等
  • 压缩后的资源文件包大约 3.1M
  • 原生语言则是 Swift + Objective-C,包括一个通知中心的插件

小红书以纯原生为主,部分使用了 React Native

  • 基本上所有的页面采用原生开发,包括首页、购物、消息、我
  • 采用 Lottie 实现动画,XYRedHouseUIKit.bundle 里有相当多的动画配置文件
  • 活动页为 Web 页面,没做离线包之类的加速
  • 商品详情、钱包、订单等少量页面为 RN 实现
  • 系统能力支持的不错,像 Widget、通知栏插件、Siri 等都用上了

两者都是原生渲染,小红书在微交互上做的不错,值得一提的是两者在跨端技术选型上均采用了 RN,既保留了性能,又支持前端丰富的生态。同时 RN 的性能也还在持续优化中,由于 2022 年下半年将 Hermes 作为默认引擎发布,意味着 RN 应用携带的是预编译(AOT)的优化后字节码,而非原始的 JS 代码,可交互时间指标减少了近一半。