ARTS 第 叁 期

目录

Algorithm

参加了周赛,题目如下:
https://leetcode.cn/problems/valid-word/
思路:
比较简单,遍历 word 中的每个字符,查看是否包含元音字母,并计数,如果字母总数和元音字母总数相同,则说明没有辅音字母。

class Solution {
public:
    bool isValid(string word) {
        //至少 包含 3 个字符。
        if (word.length() < 3 )
            return false;

        //由数字 0-9 和英文大小写字母组成。(不必包含所有这类字符。)
        //至少 包含一个 元音字母 。'a'、'e'、'i'、'o'、'u' 及其大写形式都属于 元音字母 。
        //英文中的 辅音字母 是指那些除元音字母之外的字母。
        //至少 包含一个 辅音字母 。
        std::vector<char> s{'a','e','i','o','u','A','E','I','O','U'};
        int count = 0, alpha_count  = 0;
        for(auto c : word) {
            if (!isalpha(c) &&!isdigit(c) && ( c != '@' || c != '#' || c!='$')) {
               return false;
            } else {
                if (isalpha(c)) {
                    alpha_count++;
                    if(std::find(s.begin(),s.end(),c) != s.end()) {
                        count ++;
                    }
                }

            }
        }
        if (alpha_count == count || count == 0) {
            return false;
        } else {
            return true;
        }
    }
};

Review

https://medium.com/towards-data-science/navigating-the-future-62ea60f27046
这篇文章主要探讨了自动驾驶(AV)开发中的范式转变的曙光,主要是提到使用 LLM 进行世界建模,使汽车成为一个加了摄像头和其他传感器的大型聊天机器人,使得端到端方法不再过于黑盒。

Tip

1.在星巴克连接 Wi-Fi 没有自动跳转到登录验证页面,可以使用 curl 来查看跳转地址:

curl baidu.com

2.性能测试的一种通用方法(来自极客时间 现代 C++ 编程):

  1. 把待测的代码放到一个函数里,这样容易消除一些其他干扰。
  2. 可选地,把这个函数用 attribute((noinline)) 或 __declspec(noinline) 标注为不要内联。
  3. 确保有一个依赖函数执行结果的数值会被写到某个全局变量里。根据代码的规模和组织,可以直接在这个函数里写入,或者通过外部传入的一个全局变量的指针或引用来写入。
  4. 在函数的开头和结尾测量时间,并把测得的时长累加到某个地方。
  5. 在循环里反复调用被测函数,并在每次调用函数前后进行加解锁,产生内存屏障。

如下测试 memset 例子:

char buf[80];
uint64_t memset_duration;
std::mutex mutex;

void test_memset()
{
  uint64_t t1 = rdtsc();
  memset(buf, 0, sizeof buf);
  uint64_t t2 = rdtsc();
  memset_duration += (t2 - t1);
}

int main()
{
  constexpr int LOOPS = 10000000;
  for (int i = 0; i < LOOPS; ++i) {
    std::lock_guard guard{mutex};
    test_memset();
  }
  printf("%g\n", memset_duration * 1.0 / LOOPS);
}

Share

关于 leetcode 如何训练,可以看下左耳朵耗子的这篇文章:
https://coolshell.cn/articles/12052.html

打赏作者