本周主要是做了一道关于链表相关操作的算法题目,数据库查询的题目,阅读了一篇关于 UI 自动化测试相关的英文文章,仔细学习了下 ConstraintLayout 相关的资料,后期要仔细总结一下相关的知识。

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:

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

题目相对比较简单,只是简单的链表操作。

Java

public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
if (l1 == null || l2 == null) {
return l1 == null ? l2 == null ? null : l2 : l1;
}
int upNum = 0;
ListNode current = new ListNode(0);
ListNode res = current;
while (l1 != null || l2 != null) {
int tmp = 0;
if (l1 != null) {
tmp += l1.val;
}
if (l2 != null) {
tmp += l2.val;
}
tmp += upNum;
ListNode tmpNode= new ListNode(tmp % 10);
current.next = tmpNode;
current = tmpNode;
upNum = tmp / 10;
if (l1 != null) {
l1 = l1.next;
}
if (l2 != null) {
l2 = l2.next;
}
}
if (upNum != 0) {
current.next = new ListNode(upNum);
}
return res.next;
}

Python

def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
if not l1 or not l2:
if l1:
return l1
elif l2:
return l2
else:
return None
current = ListNode(0)
res = current
upNum = 0
while l1 or l2:
tmp = 0
if l1:
tmp = tmp + l1.val
if l2:
tmp = tmp + l2.val
tmp = tmp + upNum
upNum = tmp // 10
tmpNode = ListNode(tmp % 10)
current.next = tmpNode
current = tmpNode
if l1:
l1 = l1.next
if l2:
l2 = l2.next
if upNum != 0:
current.next = ListNode(upNum)
return res.next
Runtime Memory Language
96ms 13.4 MB python
2ms 45.1 MB java

Database

181. Employees Earning More Than Their Managers

The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.

> +----+-------+--------+-----------+
> | Id | Name | Salary | ManagerId |
> +----+-------+--------+-----------+
> | 1 | Joe | 70000 | 3 |
> | 2 | Henry | 80000 | 4 |
> | 3 | Sam | 60000 | NULL |
> | 4 | Max | 90000 | NULL |
> +----+-------+--------+-----------+
>

Given the Employee table, write a SQL query that finds out employees who earn more than their managers. For the above table, Joe is the only employee who earns more than his manager.

> +----------+
> | Employee |
> +----------+
> | Joe |
> +----------+
>
SELECT 
a.Name AS Employee
FROM
Employee AS a,
Employee AS b
WHERE
a.ManagerId = b.Id AND a.Salary > b.Salary

用到的方法就是是把表查询两遍,通过对比两个表的数据来确定最后的结果。

Review

本周主要学习了和 UI 测试相关的文章,文章中用到了 Espress、Mock 框架,对异步刷新 UI 数据的情况进行了测试方法的介绍。

Espresso UI Testing With Android Architecture Components

Tips

  1. python 取余%,这一点和java一样,取整数\\,和java有所差异。
  2. 谷歌提供的新的布局ConstraintLayout,虽然可以减少布局层次,但是这个新布局measure过程相对传统布局来说较长,尤其是该布局用在ListItem的自定义 View 时,启动速度会较慢。

Share

一篇约束布局相关的文章:https://blog.csdn.net/guolin_blog/article/details/53122387