题目

The Trips table holds all taxi trips. Each trip has a unique Id, while Client_Id and Driver_Id are both foreign keys to the Users_Id at the Users table. Status is an ENUM type of (‘completed’, ‘cancelled_by_driver’, ‘cancelled_by_client’).

Id Client_Id Driver_Id City_Id Status Request_at
1 1 10 1 completed 2013-10-01
2 2 11 1 cancelled_by_driver 2013-10-01
3 3 12 6 completed 2013-10-01
4 4 13 6 cancelled_by_client 2013-10-01
5 1 10 1 completed 2013-10-02
6 2 11 6 completed 2013-10-02
7 3 12 6 completed 2013-10-02
8 2 12 12 completed 2013-10-03
9 3 10 12 completed 2013-10-03
10 4 13 12 cancelled_by_driver 2013-10-03

The Users table holds all users. Each user has an unique Users_Id, and Role is an ENUM type of (‘client’, ‘driver’, ‘partner’).

Users_Id Banned Role
1 No client
2 Yes client
3 No client
4 No client
10 No driver
11 No driver
12 No driver
13 No driver
阅读全文 »

技能补全计划:HTML5

1
2
3
4
5
6
7
8
9
<html>
<head>
<title>网页标题:技能补全计划:HTML5</title>
</head>
<body>

</body>

</html>
1
2
3
4
5
6
<!DOCTYPE html> 文档类型声明标签,表示当前界面由html书写
<html lang='zh-CN'> 只是网页语言
<head>
<meta charset="UTF-8" /> 字符集
</head>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
<h1>标题标签,h1-h6</h1>
<p>段落标签</p>
换行标签<br />
<strong>文字加粗</strong>
<b>文字加粗</b>
<em>倾斜</em> <i>倾斜</i>
<del>删除线</del> <s>删除线</s>
<ins>下划线</ins> <u>下划线</u>
<hr /><!--水平线-->
<sub>上标</sub>
<sup>下标</sup>

1
2
3
4
<div>
容器,占一行
</div>
<span>跨距,在一行</span>
阅读全文 »

题目

    • Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

      Notice that the solution set must not contain duplicate triplets.

      Example 1:

      1
      2
      Input: nums = [-1,0,1,2,-1,-4]
      Output: [[-1,-1,2],[-1,0,1]]

      Example 2:

      1
      2
      Input: nums = []
      Output: []

      Example 3:

      1
      2
      Input: nums = [0]
      Output: []

      Constraints:

      • 0 <= nums.length <= 3000
      • -105 <= nums[i] <= 105

题解

i,j,k分别代表排序后数组里三个数的索引号

因为要避免重复,一样的数组不要,所以如果任何一个位置前后两次选择的数一致就要跳过

第三个数的指针倒叙来找

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
28
29
30
class Solution {
public:
vector<vector<int>> threeSum(vector<int>& nums) {
int n=nums.size();
if(n==0) return {};
vector<vector<int>> ans;
sort(nums.begin(),nums.end());
for(int i=0;i<n;i++){
if(i>0 && nums[i]==nums[i-1]){
continue;
}
int target= -nums[i];
int k=n-1;
for(int j=i+1;j<n;j++){
if(nums[i]>0) break;
if(j>i+1 && nums[j]==nums[j-1]){
continue;
}
while(j<k && nums[j]+nums[k] > target){
k--;
}
if(j==k) break;
if(nums[j]+nums[k]==target){
ans.push_back(vector<int>{nums[i],nums[j],nums[k]});
}
}
}
return ans;
}
};
阅读全文 »

题目

Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.

k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.

Example:

Given this linked list: 1->2->3->4->5

阅读全文 »

题目

  • Given a string s, return the longest palindromic substring in s.

    Example 1:

    1
    2
    3
    Input: s = "babad"
    Output: "bab"
    Explanation: "aba" is also a valid answer.

    Example 2:

    1
    2
    Input: s = "cbbd"
    Output: "bb"

    Constraints:

    • 1 <= s.length <= 1000
    • s consist of only digits and English letters.

题解

Dp转移方程

\(P(i,j)=P(i+1,j-1)\wedge(S_i==S_j)\)

边界条件

\(P(i,i)=true\)

\(P(i,i+1)=(S_i==S_{i+1})\)

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
28
29
30
31
class Solution {
public:
string longestPalindrome(string s) {
int n=s.size();
if(n<2) return s;
int maxl=1;
int begin=0;
vector<vector<int>> dp(n,vector<int>(n));
for(int i=0;i<n;i++) dp[i][i]=1;
for(int lens=2;lens<=n;lens++){
for(int i=0;i<n;i++){
int j=i+lens-1;
if(j>=n) break;
if(s[i]!=s[j]){
dp[i][j]=0;
}else{
if(j-i<2){
dp[i][j]=1;
}else{
dp[i][j]=dp[i+1][j-1];
}
}
if(dp[i][j] && j-i+1>maxl){
begin=i;
maxl=j-i+1;
}
}
}
return s.substr(begin,maxl);
}
};
阅读全文 »

题目

Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.

According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).”

Given the following binary tree: root = [3,5,1,6,2,0,8,null,null,7,4]

img
阅读全文 »

题目

Implement int sqrt(int x).

Compute and return the square root of x, where x is guaranteed to be a non-negative integer.

Since the return type is an integer, the decimal digits are truncated and only the integer part of the result is returned.

Example 1:

阅读全文 »
0%