1、x 的平方根
class Solution {
/**
* @param x: An integer
* @return: The sqrt of x
*/
public int sqrt(int x) {
// write your code here
if (x < 0)
{
return 0;
}
double err = 1e-15;
double t = x;
while (Math.abs(t - x/t) > err * t)
t = (x/t + t) / 2.0;
return (int)t;
}
}
原文:https://blog.csdn.net/a1123612483/article/details/76229224
2、UTF-8 编码验证
public int judge(int n) {
if ((128 & n) == 0)
return -1;
if ((192 & n) == 128)//10
return 0;
if ((224 & n) == 192)
return 1;
if ((240 & n) == 224)
return 2;
if ((248 & n) == 240)
return 3;
return -2;
}
public boolean validUtf8(int[] data) {
boolean isUtf8 = false;// 当前num是否在一个验证的字符中
int times = 0;
for (int i = 0; i < data.length; i++) {
if(isUtf8==false){//当前数不在某字符编码内
times = judge(data[i]);//当前编码需要多少个10
if (times == -2 || times == 0)//非编码
return false;
if(times>0)//后面需要跟多少个10编码
isUtf8=true;
}else{
if(times>0&&judge(data[i])==0)//是10编码
times--;
else
return false;
if(times==0)
isUtf8=false;
}
}
return times>0?false:true;
}
参考:https://blog.csdn.net/yeqiuzs/article/details/52462554
3、第二高的薪水
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
set N = N - 1;
RETURN (
# Write your MySQL query statement below.
select
(select distinct
Salary
from
Employee
order by Salary desc
limit 1 offset N)
);
END
链接:https://www.jianshu.com/p/fa18ca54225a
解答2:
SELECT
(
SELECT
salary
FROM
employee
ORDER BY
salary
LIMIT 1,
1
) AS SecondHighestSalary;
链接:https://www.jianshu.com/p/66ddae52d788