当前位置:网站首页>剑指offer基础版--- 第23天
剑指offer基础版--- 第23天
2022-07-31 05:09:00 【米兰的小红黑】
class Solution {
public int majorityElement(int[] nums) {
Arrays.sort(nums);
return nums[nums.length / 2];
}
}
class Solution {
public int[] constructArr(int[] a) {
int len = a.length;
if(len == 0) return new int[0];
int[] b = new int[len];
b[0] = 1;
int tmp = 1;
for(int i = 1; i < len; i++) {
b[i] = b[i - 1] * a[i - 1];
}
for(int i = len - 2; i >= 0; i--) {
tmp *= a[i + 1];
b[i] *= tmp;
}
return b;
}
}
边栏推荐
猜你喜欢
随机推荐
[mysql improves query efficiency] Mysql database query is slow to solve the problem
【一起学Rust】Rust学习前准备——注释和格式化输出
MYSQL一站式学习,看完即学完
质量小议12 -- 以测代评
EasyExcel的简单读取操作
MySQL transaction (transaction) (this is enough..)
Minio上传文件ssl证书不受信任
关于小白安装nodejs遇到的问题(npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
MySQL优化:从十几秒优化到三百毫秒
STM32 - DMA
centos7安装mysql5.7
docker安装postgresSQL和设置自定义数据目录
ABC D - Distinct Trio (Number of k-tuples
CentOS7 —— yum安装mysql
城市内涝及桥洞隧道积水在线监测系统
DVWA shooting range environment construction
Linux的mysql报ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘ (using password NOYSE)
面试官竟然问我怎么分库分表?幸亏我总结了一套八股文
torch.normal函数用法
Numpy中np.meshgrid的简单用法示例