前端阅读体验优化-GitBook自动换肤
新键盘入手,HHKB Professional 2 Type-S
通过侦听显示器亮度,或根据当地时间,实现自动换肤换色。
新键盘入手,HHKB Professional 2 Type-S
通过侦听显示器亮度,或根据当地时间,实现自动换肤换色。
问题:
判断一个数(x)是否为 2 的 N 次幂,如果是,返回是 2^n 中的 n,如果不是返回 false
约束: x <= 2^800
不用说,递归肯定是最 sb 的版本:
function power2sb(x, n) {
n = n || 0;
if (x === 1) {
return n;
}
if (x < 1) {
return false;
}
return power2sb(x / 2, n + 1);
}
结果测试:
console.log(power2sb(4)); // 2
console.log(power2sb(5)); // false
console.log(power2sb(65536)); // 16
console.log(power2sb(Math.pow(2, 52) + 1)); // false
console.log(power2sb(Math.pow(2, 53) + 1)); // false 实际结果:53
原题地址: https://leetcode.com/problems/single-number/
Given an array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
原题地址: https://leetcode.com/problems/valid-number/
Validate if a given string is numeric.
“0” => true
“ 0.1 “ => true
“abc” => false
“1 a” => false
“2e10” => true
Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one.
原题地址: https://leetcode.com/problems/wildcard-matching/
Implement wildcard pattern matching with support for ‘?’ and ‘*‘.
‘?’ Matches any single character.
‘*‘ Matches any sequence of characters (including the empty sequence).
The matching should cover the entire input string (not partial).
The function prototype should be:
bool isMatch(const char *s, const char *p)
原题地址: https://leetcode.com/problems/spiral-matrix-ii/
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
For example,
Given n = 3
,
You should return the following matrix:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
]
// count,restime
let avg = (restime + parseFloat(val) * (count - 1)) / count;
经过反复测试,临界值为平均响应时间乘以 2 万次(如 200ms 为 400 万次),不会再变化。
如果当天请求超过平均响应时间乘以 2 万次,则不应该再计算新值。
一救援机器人有三种跳跃模式,可分别跳跃 1m,2m,3m 的距离,请用程序实现该机器人行进 n 米路程时可用的跳跃方式。
程序语言不限,当距离 n 值足够大时,程序执行时间尽量小。
例:当距离为 4 米时,输出结果有 7 种:
1m,1m,1m,1m
1m,1m,2m
1m,2m,1m
1m,3m
2m,1m,1m
2m,2m
3m,1m