cheneydog

感觉知乎越来越水了,但是还是有好作者的。

  •  
  •   cheneydog · Aug 22, 2023 · 2433 views
    This topic created in 1005 days ago, the information mentioned may be changed or developed.

    比如刚刚刷到这篇文章,

    https://zhuanlan.zhihu.com/p/641611280

    刚开始还感觉很水,越看越硬。

    4 replies    2023-08-23 10:16:00 +08:00
    lujjjh
        1
    lujjjh  
       Aug 22, 2023
    原代码的意思是,pos2 从 [0, pos1) ∪ (pos1, length) 中随机。因为区间不连续了,所以先从 [0, length-1) 中随机,再把 [pos1, length-1) 映射到 (pos1, length)。效果跟文章作者删掉 pos1 再随机的做法一样,但是时间复杂度显然是不一样的,也不需要额外空间。

    另一种常见的做法是用最后一个元素填充 pos1 的空缺,只需要改成 if (pos2 == pos1) pos2 = length - 1;
    hidemyself
        2
    hidemyself  
       Aug 22, 2023
    why 技术,这人写过好多有意思的文章
    Ericcccccccc
        3
    Ericcccccccc  
       Aug 22, 2023
    如果你关注细分领域还是有一些好的, 比如数学分类下的很多回答, 质量是不错.
    fuchaofather
        4
    fuchaofather  
       Aug 23, 2023
    非情感生活类的,纯技术领域我感觉大佬还是很多的,目前我是达不到他们的高度
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2399 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 01:19 · PVG 09:19 · LAX 18:19 · JFK 21:19
    ♥ Do have faith in what you're doing.