ARTS-week47

Algorithms

Third Maximum Number
思路: 使用set存放遍历得到的数,并保持set中的个数不超过3个,最后判断set大小是否等于3,若等于3,则返回set的第一个数,反之返回最后一个数,即最大的数。

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
public:
int thirdMax(vector<int>& nums) {
set<int> top;
for (auto num : nums) {
top.insert(num);
if (top.size() > 3) {
top.erase(top.begin());
}
}
return top.size() == 3 ? *top.begin() : *top.rbegin();
}
};

Add Strings
思路: carry记录低位的进位,两个字符串都从最后一个字符向前遍历。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public:
string addStrings(string num1, string num2) {
int i = num1.size() - 1;
int j = num2.size() - 1;
string result = "";
int carry = 0;
while (i >= 0 || j >= 0) {
if (i >= 0) {
carry += num1[i--] - '0';
}
if (j >= 0) {
carry += num2[j--] - '0';
}
result += (char)(carry % 10 + '0');
carry /= 10;
}
if (carry == 1) {
result += '1';
}
reverse(result.rbegin(), result.rend());
return result;
}
};

Review

本周阅读英文文章: IoT Security Must Evolve To Survive

Technique

学习了OpenResty相关的知识,做了笔记:
OpenResty学习笔记(一)

Share

记录一些想法:
1、去熟悉一个开源框架的使用时,务必查看官方文档,测试对应功能的状态,当官方文档没有及时跟进更新,Google搜索也找不到太多有用信息时,最好的资料就是去翻issue。

2、针对第三方提供的API,在投入使用前,应该对业务上需要的主要功能,做一个详尽的测试,校验是否有问题,制定后续跟进的方案。