ARTS第七周

Algorithm

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

You may assume the two numbers do not contain any leading zero, except the number 0 itself.

Example:

1
2
3
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8
Explanation: 342 + 465 = 807.

Answer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None

class Solution(object):
def addTwoNumbers(self, l1, l2):
"""
:type l1: ListNode
:type l2: ListNode
:rtype: ListNode
"""
carry = 0
root = n = ListNode(0)
while l1 or l2 or carry:
v1 = v2 = 0
if l1:
v1 = l1.val
l1 = l1.next
if l2:
v2 = l2.val
l2 = l2.next
carry, val = divmod(v1+v2+carry, 10)
n.next = ListNode(val)
n = n.next
return root.next

Review

https://www.quora.com/What-are-some-of-the-most-basic-things-every-programmer-should-know#

25个程序员应该知道的事情。有几个需要在平时工作中加强实践。

2.Code reviews by your peers will make all of you better. 目前公司确实没有code view,不过可以在自己组内尝试实践,增强彼此的能力。

3.Learn to Pseudo code the objective(s) before applying a language to the objective(s). (All programs break down to inputs, outputs, and manipulation, etc.) 学习伪代码,并在工作中尝试且坚持使用。

13.Look and learn constantly, but beware the shortcuts. 持续不断的学习和总结,需要持之以恒。

17.Great troubleshooters and problem solvers are true treasures if you find one. Don’t abuse it! 工作中确实没有与解决问题能力强的人太多交流,后面要关注这一点,多交流。

文中提到一点关于上级,对该观点存疑。
21.Make your boss look good always. If you don’t like or respect or if you can’t learn anything more from your boss, seek a new one immediately.

Tip

概念

对网站常用数据指标进行汇总。

PV Page View,页面访问量 用户每次对网站中的网页访问一次记录一次,用户对同一个网页多次刷新,访问量累计。

UV Unique Visitor 独立访客。基于客户端cookie实现,用户对同一个网页多次访问指计算一次,访问量不统计。

DAU Daily Active User 日活跃用户。DAU通常统计一日(统计日)之内,登录或使用了某个产品的用户数(去除重复登录的用户),这与流量统计工具里的访客(UV)概念相似。

TPS Transactions Per Second 每秒处理事务数。

QPS Queries Per Second 每秒处理查询数。

RPS Requests Per Second的缩写,每秒能处理的请求数目,等效于QPS。

并发数 系统同时能处理的请求数量,这个也是反应了系统的负载能力。

计算

峰值QPS:

原理:每天80%的访问集中在20%的时间里,这20%时间叫做峰值时间

公式:( 总PV数 80% ) / ( 每天秒数 20% ) = 峰值时间每秒请求数(QPS)

QPS(TPS)、并发数、响应时间它们三者之间的关系是:

QPS(TPS)= 并发数 / 平均响应时间
并发数 = QPS * 平均响应时间

Share

https://stackify.com/unit-testing-basics-best-practices/
极客时间左耳听风专栏中推荐的一篇文章。文章首先划定什么不是单元测试。然后从最原始的方式开始引入单元测试框架,对于初学者来说值得一看。