[LeetCode 70,83][简单]爬楼梯/删除排序链表中的重复元素

LeetCode-50 快速幂运算 LeetCode-50 快速幂运算 实现 pow(x, n) ,即计算 x 的 n 次幂函数。 示例 1: 输入: 2.00000, 10 输出: 1024.00000 示例 2: 输入: 2.10000, 3 输出: 9.26100 示例 3: 输入: 2.00000, -2 输出: 0.25000 解释: 2-2... 阅读详情

70.爬楼梯
题目链接
根据递推公式写一个快速幂,矩阵形式如下
A = ( 1 1 1 0 ) A = \left( \begin{array}{cc} 1 & 1\\ 1 & 0 \end{array} \right) A=(11​10​)
当然递推公式也可以写成解析形式的解,有兴趣可以了解下线性齐次递推式的解

class Solution {
    typedef long long LL;
public: 
    struct Mat{
        LL a[2][2];
        Mat(){memset(a,0,sizeof a);};
        Mat(LL q){memset(a,0,sizeof a);for(int i = 0;i < 2; i++)a[i][i] = q;}
        Mat operator * (const Mat &B){
            Mat C;
            for(int i = 0; i < 2; i++){
                for(int k = 0 ;k < 2; k++){
                    if(!a[i][k])continue;
                    for(int j = 0; j < 2; j++){
                        C.a[i][j] += a[i][k] * B.a[k][j];
                    }  
                }
            }
            return C;
        }
        Mat operator ^ (int p){
            Mat ans(1);
            Mat A = *this;
            while(p){
                if(p&1)ans = ans * A;
                p >>= 1;
                A = A * A;
            }
            return ans;
        }
    };

    int climbStairs(int n) {
        if(n==0||n==1)return 1;
        Mat A;A.a[0][0] = A.a[0][1] = A.a[1][0] = 1;
        A = A ^ (n-1);
        return A.a[0][0] + A.a[0][1];    
    }
};

83.删除排序链表中的重复元素
题目链接

class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        ListNode *st = head;
        while(st!=NULL&&st->next!=NULL){
            if(st->val==st->next->val)st->next = st->next->next;
            else st = st -> next;
        }
        return head;
    }
};
电磁波函数复数表示法:为什么物理学家偏爱e^(ikz)而非cos(kr-wt)? 本文深入解析了电磁波函数复数表示法(如e^(ikz))相较于传统余弦形式的巨大优势。通过欧拉公式,复数形式将复杂的三角运算转化为简洁的指数运算,在微分、积分、线性叠加及处理相位时展现出极高的计算效率,是物理学家和工程师分析波动现象的核心工具。 阅读详情

相关推荐

统信UOS专业版服务器无人值守安装

(2)、专业版:主要针对整机厂商、政府单位、事业单位和企业用户使用,cpu目前支持x86、arm、mips、sw64和LoogngArch架构,试用期免费获得90天的使用,随后需要单位采购授权,获得正式激活码后才可以正常使用。其中企业版代号为d,行业版为a/c,欧拉版则为e,在最近的更新中,c版已经停止更新迭代,后续行业版本将都为a版,版本代号体现在镜像名字中以及版本号上,例如1050d则表示企业版1050版本。UOS系统服务器版本分为:专业版(d版)、行业版(a版)、欧拉版(e版)

靠谱运维 2254

Leetcode算法——70、爬楼梯(climbing stairs)

你正在爬楼梯,共有 n 层台阶。 每次可以爬 1 层或 2 层。 问有多少种不重复的方法可以从楼梯底爬到楼梯顶。 思路 爬n层台阶,可以根据第一步的层数,将所有爬法分为两类: 第一步爬1层,然后继续爬剩下的n-1层 第一步爬2层,然后继续爬剩下的n-2层 这两种方法是互斥且完备的。 因此,n层的爬法 = (n-1) 层的爬法 + (n-2) 层的爬法。 即斐波那契数列。 python实现 de...

HappyRocking的专栏 831

VerilogEval实战指南:从基准测试到模型微调的全流程解析

本文提供了VerilogEval实战指南,详细解析了从基准测试到模型微调的全流程。VerilogEval是一个自动化、标准化的测试框架,用于客观评估大语言模型生成Verilog硬件代码的能力。文章涵盖了环境搭建、核心机制解析、利用其生成合成数据进行模型微调的策略,以及如何将其工程化集成到自动化评估流程中,为硬件设计领域的AI应用提供了完整的方法论。

yy01234的博客 1005

算法-leetcode-每日一题-快速幂

分析:A的n次方,将n看成二进制!例如n为5,二进制101。看下图。所以每一次都要消耗一个二进制位,而且要用一个数字来保存当前二进制位累乘的值。 public static void questPos(int a, int n) { int base = a;//base用来保存当前二进制位的累乘值 int res = 1; while(n != 0) { ...

wujingchangye的博客 432

Python实战:3步搞定视频去重,告别重复文件烦恼(附完整代码)

本文提供了一套基于Python的视频去重实战方案,通过三步流程(抽帧、生成内容指纹、相似度比对)高效识别重复视频文件。文章详细介绍了使用dHash算法生成视频指纹的核心原理,并提供了完整的代码实现,帮助用户快速构建自己的视频去重工具,告别重复文件管理烦恼。

weixin_29054245的博客 382

瑞数6.5逆向实战:手把手教你用RPC搞定cookie sign加密(附环境补全技巧)

本文深入解析瑞数6.5逆向实战,重点探讨如何结合环境补全与RPC调用技术来应对其动态加密机制。文章详细介绍了环境指纹采集、双重验证等核心防护原理,并提供了基于Puppeteer的RPC实现方案,手把手教你搞定cookie sign加密,附有实用的环境补全技巧与完整代码示例。

weixin_29315091的博客 1273

Leetcode practice (6)

Climbing Stairs 题目描述:爬楼梯,一次只能爬1step or 2step,给定一个非负数,问有多少种不重复的爬法。 思路:乍看一下题目,还在思考如何枚举出所有可能的情况,eg,给定2,那么组合就是【1,1】,【2】;给定3,那么组合就是【1,1,1】【1,2】【2,1】, 其实用递归的思路去想就是当元素值等于1 or 等于2时,停止。后面发现该题目就是Fibonacci数列的...

儒雅,勤思,博学 208

OCSP环境搭建--Windows Server 2016

OCSP环境搭建--Windows Server 2016 一. OCSP环境中相关信息 1. 服务器1 操作系统:Win Server 2016 Standard版 IP地址:172.16.0.19/23,网关:172.16.0.1,首选DNS:127.0.0.1 服务器角色:域控制器、证书颁发机构、radius服务器、DNS服务器 ...

CsdnCHong_566的博客 3352

leetcode刷题笔记(简单篇):70&83

语法: CREATE FUNCTION 函数名(参数名 参数类型,...) RETURNS 返回类型 BEGIN 函数体 END 注:1.参数列表包含两部分:参数名和参数类型 2.函数体:必须有return语句,否则会报错。 3.若函数体中仅有一条语句,则可以省略BEGIN END 4.使用delimiter语句设置结束标记 ...

光脚小孩的博客 174

PCB压合原理与工艺全流程深度解析

PCB压合是多层印制电路板制造中的核心工序,其本质并非简单物理叠加,而是高分子树脂流动、玻璃布应力释放、铜箔热膨胀及界面能调控的协同过程。理解压合原理,需掌握温度-压力-时间三维曲线动态关系;优化工艺流程,须兼顾叠板精度、热压参数匹配与冷却策略;关键影响因素如半固化片(PP)选型、铜箔表面处理、设备温场均匀性、结构对称性、环境湿度及操作手法,共同决定层间结合力、翘曲度与孔壁质量。本文围绕PCB压合原理、工艺流程、关键影响因素三大维度展开,融合IPC标准、实测数据与产线案例,为工艺工程师、NPI人员及设备维护

weixin_29191081的博客 258

StarCCM+ 导入STL几何模型进行仿真

通过 Import Surface Mesh 的方法导入 STL 文件进行仿真

薛定谔的alpha狗 6131

[LeetCode 21,26,27][简单]合并两个有序链表/删除排序数组中的重复项/移除元素

21.合并两个有序链表 题目链接 直接比过去,把原来的链表拼起来,当然也可以拿值new过去。 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }...

IDrandom的专栏 1638

Autosar EcuM配置-初始化及下电执行函数-基于ETAS软件

Autosar EcuM学习笔记-上电初始化执行函数及下电前执行函数,本文介绍在EcuM中的配置及使用。

赞的博客 851

[LeetCode 299,303][简单]猜数字游戏/区域和检索 - 数组不可变

299.猜数字游戏 题目链接 class Solution { public: string getHint(string secret, string guess) { ios::sync_with_stdio(0); cin.tie(0); int a[10]={0},b[10]={0}; int acnt=0,bcnt=...

IDrandom的专栏 474

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

[LeetCode 1365~1368][周赛]周赛178题解

5344.有多少小于当前数字的数字 题目链接 static const auto io_speed_up = [](){ ios::sync_with_stdio(false); cin.tie(0); return 0; }(); class Solution { public: vector<int> smallerNumbersThanCurren...

IDrandom的专栏 369

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

[LeetCode 14,20][简单]最长公共前缀/有效的括号

14.最长公共前缀 题目链接 class Solution { public: string longestCommonPrefix(vector<string>& strs) { if(strs.size()==0)return ""; int l= strs[0].length(); for(int i=1;i<...

IDrandom的专栏 368

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

[LeetCode 1360~1363][周赛]周赛177题解

1360.日期之间隔几天 题目链接 static const auto io_speed_up = [](){ ios::sync_with_stdio(false); cin.tie(0); return 0; }(); class Solution { public: int nleap[13]={0, 31, 28, 31, 30, 31, 30, 31, 3...

IDrandom的专栏 353

[LeetCode 1351~1354][周赛]周赛176题解

这场周赛还是有点意思的,没有那么水,大概hard有cf div2 D的感觉 1351. 统计有序矩阵中的负数 题目链接 第一种:二分 static const auto io_speed_up = [](){ ios::sync_with_stdio(false); cin.tie(0); return 0; }(); class Solution { public: ...

IDrandom的专栏 338

[LeetCode 169,171][简单]多数元素/Excel表列序号

169.多数元素 题目链接 比较显然的做法是排个序后取中间元素和哈希表 看了下题解发现最后一个方法比较巧妙,叫做Boyer-Moore 投票算法,就是先把第一个元素设置为候选,然后循环过程中对候选+1,非候选 -1,到零后把下一个元素置为候选,最后的候选就是真值,简单证明下: 候选为真,则最多删掉同样数量的候选与非候选 候选为假 删掉更多的非候选,对结果无影响 删掉同样多的非候选与候选 真...

IDrandom的专栏 335

[LeetCode 190,191][简单]颠倒二进制位/位1的个数

190.颠倒二进制位 题目链接 贴一个纯位运算的版本和一个纯bitset的版本 class Solution { public: uint32_t reverseBits(uint32_t n) { bitset<32>a(n); string tmp = a.to_string(); reverse(tmp.begin(), t...

IDrandom的专栏 319

[LeetCode 404, 405][简单]左叶子之和/数字转换为十六进制数

404.左叶子之和 题目链接 static const auto io_speed_up =[](){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; }(); class Solution { public: int sumOfLeftLeaves(TreeNode* root...

IDrandom的专栏 311

[LeetCode 172,189][简单]阶乘后的零/旋转数组

172.阶乘后的零 题目链接 10 = 2 * 5,比n小是2的倍数的数肯定比是5的多,所以只需要看因子5出现的次数 class Solution { public: int trailingZeroes(int n) { int ans = 0; while(n){ n/=5; ans += n; ...

IDrandom的专栏 310

[LeetCode 198,202][简单]打家劫舍/快乐数

198.打家劫舍 题目链接 dp[n]=max(dp[n−1],dp[n−2]+w[n])dp[n] = max(dp[n-1],dp[n-2]+w[n])dp[n]=max(dp[n−1],dp[n−2]+w[n]) 可以滚动优化一下空间 class Solution { public: int rob(vector<int>& nums) { int...

IDrandom的专栏 309

[LeetCode 374,383][简单]猜数字大小/赎金信

374.猜数字大小 题目链接 static const auto io_speed_up = []() { ios::sync_with_stdio(0); cin.tie(0); return 0; }(); int guess(int num); class Solution { public: typedef long long LL; int gu...

IDrandom的专栏 302

[LeetCode 263,268][简单]丑数/缺失数字

263.丑数 题目链接 class Solution { public: bool isUgly(int num) { while(num&&(num&1)==0)num>>=1; while(num&&(num%3)==0)num/=3; while(num&&(num%5...

IDrandom的专栏 296

[LeetCode 326,342][简单]3的幂/4的幂

326.3的幂 题目链接 比较好想的是取对数法。 class Solution { public: double eps = 1e-11; bool isPowerOfThree(int n) { if(n<=0)return 0; double pw = log2(n) / log2(3.0); return fabs(rou...

IDrandom的专栏 288
上一篇: [LeetCode 67,69][简单]二进制求和(模拟)/x的平方根(牛顿法)
下一篇: [LeetCode 88,100][简单]合并两个有序数组/相同的树
IDrandom
博客等级 码龄12年 31粉丝 125原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值