当前位置:网站首页>LeetCode_22_Apr_4th_Week
LeetCode_22_Apr_4th_Week
2022-08-04 06:29:00 【KuoGavin】
It's really unpredictable,If something happened to the relatives in the middle, there is no energy to continue to brush the questions.Fortunately, this time node can take more care of her,The situation has now stabilized,The environment is almost configured,Pick it up again.I wish you all good health,生活如意!
April 25th : 398. 随机数索引
April 26th : 883. 三维形体投影面积
April 25th : 398. 随机数索引
Mainly the setting and use of random seeds:
srand((unsigned)time(NULL));
rand()%num //等概率获取0~num-1之间的任一数字
解题代码如下:
class Solution {
public:
Solution(vector<int>& nums) {
srand((unsigned)time(NULL));
for(int i = 0; i < nums.size(); ++i) keys[nums[i]].push_back(i);
}
int pick(int target) {
return keys[target][rand()%keys[target].size()];
}
private:
unordered_map<int, vector<int>> keys;
};
Comment There is a reservoir principle here,挺有意思的,The efficiency is also higher than the above method
class Solution {
public:
vector<int> res;
Solution(vector<int>& nums) {
res = nums;
}
int pick(int target) {
int c = 0, index = 0;
for(int i = 0;i < res.size();i++)
if(res[i] == target){
c++;
if(rand() % c == 0) index = i;
}
return index;
}
};
April 26th :April 26th : 883. 三维形体投影面积
The problem is that the area is ,The sum of the maximum values for each column+The sum of the maximum values for each row+非0行列数目,解题代码如下:
class Solution {
public:
int projectionArea(vector<vector<int>>& grid) {
int overLookView = 0, leftLookView = 0, rightLookView = 0;
int rowMax = 0, colMax = 0; //Traversal of multiplexed rows and columns,只需交换i,j的位置即可
for(int i = 0; i < grid.size(); ++i) {
rowMax = 0, colMax = 0;
for(int j = 0; j < grid[i].size(); ++j) {
overLookView += grid[i][j] ? 1 : 0;
rowMax = max(grid[i][j], rowMax);
colMax = max(grid[j][i], colMax);
}
leftLookView += rowMax;
rightLookView += colMax;
}
return overLookView + leftLookView + rightLookView;
}
};
边栏推荐
- Rules.make-适合在编辑模式下看
- 中国联通、欧莱雅和钉钉都在争相打造的秘密武器?虚拟IP未来还有怎样的可能
- target has libraries with conflicting names: libcrypto.a and libssl.a.
- Copy攻城狮5分钟在线体验 MindIR 格式模型生成
- PCL1.12 解决memory.h中EIGEN处中断问题
- MNIST Handwritten Digit Recognition - Image Analysis Method for Binary Classification
- Cut the hit pro subtitles export of essays
- arm-2-基础阶段
- 【论文阅读】Multi-View Spectral Clustering with Optimal Neighborhood Laplacian Matrix
- 度量学习(Metric learning)—— 基于分类损失函数(softmax、交叉熵、cosface、arcface)
猜你喜欢

安装pyspider后运行pyspider all后遇到的问题

Brief description of database and common operation guide

Golang环境变量设置(二)--GOMODULE&GOPROXY

集合--LinkedList

剪映专业版字幕导出随笔

AWS uses EC2 to reduce the training cost of DeepRacer: DeepRacer-for-cloud practical operation

Install Minikube Cluster in AWS-EC2

第三章 标准单元库(上)

lstm pipeline 过程理解(输入输出)

深度确定性策略梯度(DDPG)
随机推荐
Deep learning, "grain and grass" first--On the way to obtain data sets
MNIST Handwritten Digit Recognition - Lenet-5's First Commercial Grade Convolutional Neural Network
Introduction to Convolutional Neural Networks
投稿相关
(导航页)OpenStack-M版-双节点手工搭建-附B站视频
Fabric v1.1 环境搭建
[开发杂项][编辑器][代码阅读]ctags&vim
安装MySQL的详细步骤
yoloV5 使用——训练速度慢,加速训练
Copy攻城狮5分钟在线体验 MindIR 格式模型生成
MNIST手写数字识别 —— 图像分析法实现二分类
MNIST手写数字识别 —— 从感知机到卷积神经网络
机器学习——分类问题对于文字标签的处理(特征工程)
第一章 绪论
深度学习理论 —— 初始化、参数调节
【论文阅读】Multi-View Spectral Clustering with Optimal Neighborhood Laplacian Matrix
"A minute" Copy siege lion log 】 【 run MindSpore LeNet model
MOOSE平台使用入门攻略——如何运行官方教程的例子
数据库的简述与常用操作指南
抽象类、内部类和接口