题目

Given two straight line segments (represented as a start point and an end point), compute the point of intersection, if any. If there's no intersection, return an empty array.

The absolute error should not exceed 10^-6. If there are more than one intersections, return the one with smallest X axis value. If there are more than one intersections that have same X axis value, return the one with smallest Y axis value. Example 1:

Input: line1 = {0, 0}, {1, 0} line2 = {1, 1}, {0, -1} Output: {0.5, 0} Example 2:

Input: line1 = {0, 0}, {3, 3} line2 = {1, 1}, {2, 2} Output: {1, 1} Example 3:

阅读全文 »

题目

You are given K eggs, and you have access to a building with N floors from 1 to N.

Each egg is identical in function, and if an egg breaks, you cannot drop it again.

You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floor F will not break.

Each move, you may take an egg (if you have an unbroken one) and drop it from any floor X (with 1 <= X <= N).

阅读全文 »

题目

Given an input string, reverse the string word by word.

Example 1:

Input: "the sky is blue" Output: "blue is sky the" Example 2:

Input: " hello world! " Output: "world! hello" Explanation: Your reversed string should not contain leading or trailing spaces. Example 3:

阅读全文 »

题目

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

For example, given n = 3, a solution set is:

[ "((()))", "(()())", "(())()", "()(())", "()()()"]

题解

阅读全文 »

题目

地上有一个m行n列的方格,从坐标 [0,0] 到坐标 [m-1,n-1] 。一个机器人从坐标 [0, 0] 的格子开始移动,它每次可以向左、右、上、下移动一格(不能移动到方格外),也不能进入行坐标和列坐标的数位之和大于k的格子。例如,当k为18时,机器人能够进入方格 [35, 37] ,因为3+5+3+7=18。但它不能进入方格 [35, 38],因为3+5+3+8=19。请问该机器人能够到达多少个格子?

示例 1:

输入:m = 2, n = 3, k = 1 输出:3 示例 1:

输入:m = 3, n = 1, k = 0 输出:1 提示:

阅读全文 »

题目

You are given an n x n 2D matrix representing an image.

Rotate the image by 90 degrees (clockwise).

Note:

You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.

阅读全文 »

题目

表1: Person

列名 类型
PersonId int
FirstName varchar
LastName varchar

PersonId 是上表主键 表2: Address

列名 类型
AddressId int
PersonId int
City varchar
State varchar
阅读全文 »

数据库学习笔记——关系数据库

关系

定义1 域是一组具有相同数据类型的值的集合。

定义2 给定一组域\(D_1,D_2,\cdots,D_n\),允许其中某些域是相同的,\(D_1,D_2,\cdots,D_n\)的笛卡尔积定义为 \[ D_1 \times D_2 \times\cdots\times D_n=\{(d_1,d_2,\cdots,d_n)|d_i \in D_i,i=1,2,\cdots,n\} \] 其中,每一个元素\((d_1,d_2,\cdots,d_n)\)叫做一个n元组(n-tuple),或简称元组(tuple)。元素中每一个值\(d_i\)叫做一个分量(component)。

一个域中允许的不同取值的个数称为这个域的基数(cardinal number)。

\(D_i(i=1,2,\cdots,n)\)为有限集,其基数为\(m_i(i=1,2,\cdots,n)\),则\(D_1\times D_2 \times\cdots\times D_n\)的基数M为 \[ M=\mathop{\Pi}\limits_{i=1}^{n} m_i \]

定义3 \(D_1 \times D_2 \times\cdots\times D_n\)的子集叫做在域\(D_1,D_2,\cdots,D_n\)的关系,表示为\(R(D_1,D_2,\cdots,D_n)\)

这里R表示关系的名字,n表示关系的目或度(degree)。

若关系中某一属性组的值能唯一地标识一个元组,而其子集不能,则称该属性组为候选码(candidate key)。

候选码的诸属性称为主属性(prime attribute)。不包含在候选码中的属性称为非主属性(non-prime attribute)或非码属性(no-key attribute)。

若一个关系有多个候选码,则选定一个为主码(primary key)。极端情况下,关系模式的所有属性是这个关系模式的候选码,称为全码。

阅读全文 »

数据库学习笔记——并发控制

为了保证事务的隔离性和一致性,数据库管理系统需要对并发操作进行正确调度。

并发操作带来的不一致性包括修改丢失(lost update)、不可重复读(non-repeatable read)、读“脏”数据(dirty row).

并发控制的主要技术有封锁(locking)、时间戳(timestamp)、乐观控制法(optimistic scheduler)和多版本并发控制(multi-version concurrency control,MVCC)等。

封锁

阅读全文 »
0%