CodingTour
ARTS #144

Algorithm

本周选择的算法题是:Is Subsequence

规则

Given two strings s and t, return true if s is a subsequence of t, or false otherwise.

A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., "ace" is a subsequence of "abcde" while "aec" is not).

Example 1:

Input: s = "abc", t = "ahbgdc"
Output: true

Example 2:

Input: s = "axc", t = "ahbgdc"
Output: false

Constraints:

  • 0 <= s.length <= 100
  • 0 <= t.length <= 104
  • s and t consist only of lowercase English letters.

Follow up: Suppose there are lots of incoming s, say s1, s2, ..., sk where k >= 109, and you want to check one by one to see if t has its subsequence. In this scenario, how would you change your code?

Solution

class Solution:
    def isSubsequence(self, s: str, t: str) -> bool:
        sp, tp = 0, 0
        while sp < len(s) and tp < len(t):
            sp += int(s[sp] == t[tp])
            tp += 1
        return sp == len(s)

Review

If the Backend API Returns 100,000 Records at One Time, How Should We Handle it in the Frontend?

这篇短文不错,虽然实际场景下的答案应该是优化掉后端代码或是写下这段代码的人,但本文的真实用意是如何提高前端应用的渲染性能,并介绍了几种从初级到高级的方法,其中有两个我不了解的 API:

  • requestAnimationFrame
    • 相比 setTimeoutsetIntervalrequestAnimationFrame 会把一帧中的 DOM 操作汇总起来,在一次重绘或回流中完成,并且重绘或回流的时间间隔紧紧跟随浏览器的刷新频率,一般来说,这个频率为每秒 60 帧
    • 如果是在隐藏或不可见的元素中,requestAnimationFrame 不会进行任何重绘或回流,这意味着没有额外的 CPU、GPU 和内存消耗
  • Document Fragment
    • 将 DocumentFragment 作为临时的 DOM 节点存储器,当对 DocumentFragment 修改完成时,可以将其中的节点一次性加入 DOM 树,从而减少回流次数,达到性能优化的目的

学到了。

Tip

Wordle 游戏不错~

Share

最近读《格鲁夫给经理人的第一课》时了解到知识权和管理权的理论,说下我的理解。

现在流行的管理风格是希望决策是由离问题最近,而且最了解问题的人来做出的,就像 Google、Netflix 提出的 “Context, not control”,指令不是单纯的上传下达,而是通过提供上下文,建立内部信息透明的机制来解决问题、做出决策,从而提高企业整体的运营效率。

其中的:

  • “最了解问题”就是知识权
  • “做出决策”就是管理权

在过往经历中掌握了知识和技能的人,为自己争取到了知识权,而在组织中拥有职位力量的人,则是为自己争取到了管理权,在当前竞争时间的时代,加速信息传递的速度和提高决策效率就是企业最大的杠杆。只有将知识权和管理权结合起来,做到双权合一,才能真正“让最懂一线的人做一线的决策”,而随着时间的推移,要不断地做动态再平衡:知识权扩大了,那么相应的管理权也要跟着扩大;反之则缩小。

是一个挺有趣和实用的理论。