[leetcode]大可日常打卡1

在C++中,NULL和nullptr有什么区别? 这两个定义导致了冲突,C++中的NULL如果和C语言一样也是(void *)0指针,而C++不允许void*隐式转换成其它指针类型,那NULL就无法表示空指针了。因此,使用 nullptr可以增加代码的清晰性,避免类型安全问题。即使在混合C++和C代码时,nullptr也提供了一个明确无误的空指针表示,达到兼容的目的。C++11 引入 nullptr 彻底解决了这些问题,提高语言的安全性、清晰性和现代性。在了解NULL和nullptr背后的故事之后,相信大家以后再也不会用NULL了。 阅读详情

344. Reverse String

class Solution {
    public String reverseString(String s) {
        if(s==null||s.length()==0){
            return s;
        }
		StringBuilder sb=new StringBuilder();
		for(int i=s.length()-1;i>=0;i--){
			sb.append(s.charAt(i));
		}
		return sb.toString();
    }
}

434. Number of Segments in a String

class Solution {
    public int countSegments(String s) {
        if(s==null||s.length()==0){
            return 0;
        }
        String[] arr=s.split(" ");
        int count=0;
        for(int i=0;i<arr.length;i++){
        	if(arr[i].length()!=0){
        		count++;
        		System.out.println(i+":"+arr[i]);
        	}else{
        		continue;
        	}
        	
        }
        return count;
        
    }
}

617. Merge Two Binary Trees

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    public TreeNode mergeTrees(TreeNode t1, TreeNode t2) {
        if(t1==null&&t2==null){
            return null;
        }
        if(t1==null){
            return t2;
        }
        if(t2==null){
            return t1;
        }
        TreeNode res=new TreeNode(t1.val+t2.val);
        
        res.left=mergeTrees(t1.left,t2.left);
        res.right=mergeTrees(t1.right,t2.right);
        return res;
    }
    
    
}

669. Trim a Binary Search Tree

    如果是空,返回root;如果满足条件,那么当前节点要留着,左孩子等于左子树递归后返回的根节点的值,右孩子等于右子树递归后返回的根节点的值;如果不满足条件,小于L,那么直接把右子树递归的结果换成当前节点,大于R,把左子树递归的结果换成当前节点。

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    public TreeNode trimBST(TreeNode root, int L, int R) {
        if(root==null){
            return root;
        }
        if(root.val>=L&&root.val<=R){
            root.left=trimBST(root.left,L,R);
            root.right=trimBST(root.right,L,R);
        }else if(root.val<L){
            
            root=trimBST(root.right,L,R);
        }else if(root.val>R){
            
            root=trimBST(root.left,L,R);
        }
        return root;
    }
}
832. Flipping an Image
import java.util.Stack;
class Solution {
    public int[][] flipAndInvertImage(int[][] A) {
        if(A==null){
            return null;
        }
        
        for(int i=0;i<A.length;i++){
            Stack<Integer> stack=new Stack<Integer>();
            for(int j=0;j<A[0].length;j++){
                stack.add(oneZeroChange(A[i][j]));
            }
            for(int j=0;j<A[0].length;j++){
                A[i][j]=stack.pop();
            }
        }
        return A;
    }
    public int oneZeroChange(int x){
        if(x==1){
            return 0;
        }
        return 1;
    }
}

766. Toeplitz Matrix

    看到的时候没思路,想遍历,但是发现如果是左下角和右上角的点的话,就不好操作,还得多加判断。

    思路:每一行对角线上的数的共同特征就是i-j都一样,建立一个hashmap,把一个对角线上的数的i-j当成key存进去,如果值有不一样的话,那么就说明不是Toeplitz矩阵。

import java.util.HashMap;
class Solution {
    public boolean isToeplitzMatrix(int[][] matrix) {
        if(matrix==null||matrix.length==0||matrix[0].length==0){
            return true;
        }
		HashMap<Integer,Integer> map=new HashMap<>();
        for(int i=0;i<matrix.length;i++){ //行
            for(int j=0;j<matrix[0].length;j++){  //列
                if(!map.containsKey(i-j)){
                	map.put(i-j, matrix[i][j]);
                }else{
                	if(map.get(i-j)!=matrix[i][j]){
                		return false;
                	}
                }
            }
        }
		return true;
    }
}

深度学习工具包 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") 立即下载

相关推荐

提升AI智能体回复质量:扣子平台提示词优化技巧与案例解析

本文深入探讨了在扣子平台上优化AI智能体提示词的关键技巧与实战案例。通过分析提示词设计的核心原则、业务场景适配策略以及平台高级功能应用,帮助开发者显著提升AI Agent的回复质量。文章特别强调了结构化提示词设计和A/B测试评估的重要性,并提供了电商客服场景的完整优化案例。

weixin_30897233的博客 540

【小Y学算法】⚡️每日LeetCode打卡⚡️——33.杨辉三角

算法题打卡:杨辉三角。没有特别幸运,那么请先特别努力,别因为懒惰而失败,还矫情地将原因归于自己倒霉。所以说,树倒了,没有一片雪花是无辜的

努力前行,总会成为自己心中的那道光 9573

Cadence Allegro 17.2 PCB设计避坑指南:从焊盘制作到封装绘制的完整流程

本文详细解析了Cadence Allegro 17.2在PCB设计中的关键操作技巧,从焊盘制作到封装绘制的完整流程。通过0402电阻和2.54mm排针的实例,揭示新手常见错误及解决方案,包括焊盘参数设置、层类型区分和坐标输入规范,帮助工程师避免设计返工和生产事故。

weixin_28683391的博客 409

前端小白的力扣打卡日常-1779

前言 本人身为一个前端小白,一开始就没怎么接触过算法。想着做前端应该也不太需要去学算法,但是最近看到各种面试经历的文章以及身边一些人的面试经历,都说明了算法的重要性,从现在开始我也要慢慢来,先从打卡力扣每日一题开始! 题目内容 「1779. 找到最近的有相同 X 或 Y 坐标的点。」 给你两个整数 x 和 y ,表示你在一个笛卡尔坐标系下的 (x, y) 处。同时,在同一个坐标系下给你一个数组 points ,其中 points[i] = [ai, bi] 表示在 (ai, bi) 处有一个点。当一个点与你

weixin_51217727的博客 261

Buck-Boost电路实战:如何用LM2596模块快速搭建升降压电源(附元件选型指南)

本文详细介绍了如何使用LM2596模块快速搭建Buck-Boost升降压电路,包括硬件选型、电路搭建、示波器实测和进阶技巧。通过实测数据和避坑指南,帮助电子工程师解决电压不稳定、效率低下等常见问题,提升DC-DC变换器的设计水平。

weixin_30485379的博客 112

ARM芯片内部的高速公路:手把手教你用AMBA Designer配置NIC-400互连控制器

本文详细介绍了如何使用AMBA Designer工具配置ARM芯片中的NIC-400互连控制器,涵盖从基础拓扑构建到高级QoS设置的完整流程。通过实际案例演示,帮助开发者掌握AXI协议下的高效片上网络设计,提升SoC性能与能效比。

weixin_26750481的博客 315

【小Y学算法】⚡️每日LeetCode打卡⚡️——26.相同的树

算法题打卡:相同的树。没有特别幸运,那么请先特别努力,别因为懒惰而失败,还矫情地将原因归于自己倒霉。所以说,树倒了,没有一片雪花是无辜的

努力前行,总会成为自己心中的那道光 9773

【LTspice】002 第一个仿真电路

目录 1. 光偶元件的工作原理 2. 过零检测电路的工作原理 3. 以PC817光耦搭建一个过零检测电路 1. 光偶元件的工作原理 光耦合器(optical coupler,英文缩写为OC)亦称光电隔离器或光电耦合器,简称光耦。它是以光为媒介来传输电信号的器件。 PC817是一种把红外光发射器件和红外光接受器件以及信号处理电路等封装在同一管座内的器件。当输入电信号加到输入端发光器件LED上,LED发光,光接受器件接受光信号并转换成电信号,然后将电信号直接输出,或者将电信号放大处理成标准数字电平输

m0_59642765的博客 8024

LeetCode打卡集锦

LeetCode 是一个非常棒的 OJ(Online Judge)平台,收集了许多常见的算法面试题目,同时还收录很多互联网公司的题库内容。如果为了面试刷题,LeetCode绝对是一个绝佳的选择。即使不为了跳槽面试,作为一个程序员,通过LeetCode保持手感也是不错的选择。本人就是平时刷刷题,在LeetCode上打打卡,告诉自己除了日常工作内容,还能做一些自己感兴趣的事情。 话不多说,看看最新刷过的题目列表,这仅仅是个开始。 LeetCode之两数之和(一) LeetCode之两数相加(二) Lee

liuzhen007的专栏 954

Informer:比Transformer更有效的长时间序列预测

目录 AAAI 2021最佳论文:比Transformer更有效的长时间序列预测 Background Why attention Methods:the details of Informer Solve_Challenge_1:最基本的一个思路就是降低Attention的计算量,仅计算一些非常重要的或者说有代表性的Attention即可,一些相近的思路在近期不断的提出,比如Sparse-Attention,这个方法涉及了稀疏化Attention的操作,来减少Attention计算量,然后涉及的

To be a better man 1万+

在 RAP 里把编号这件事做得既优雅又合规:Early Numbering 与 Late Numbering 的落地指南

本文探讨了 SAP RAP 框架中的三种主键编号策略及其适用场景。文章首先指出传统 ABAP 应用中主键处理的局限性,详细分析了早期编号(外部/内部)和延迟编号的差异,强调延迟编号在避免业务断号方面的优势。通过 Partner 业务对象案例,文章演示了延迟编号的实现方法,包括行为定义配置、保存类实现和编号分配逻辑。同时指出测试中常见的校验陷阱,并提醒生产环境应避免简单的 MAX+1 方案,建议采用原子取号机制确保并发安全。全文从业务合规性和技术实现两个维度,为 RAP 应用的编号策略选择提供了实用指导。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1849

力扣日常打卡112.路径总和

题目描述: 给定一个二叉树和一个目标和,判断该树中是否存在根节点到叶子节点的路径,这条路径上所有节点值相加等于目标和。 示例: 思路及实现: 根据题目很容易想到dfs算法,若dfs有一条路径返回true,则整体返回true。 转化为代码即为: bool left,right; left = dfs(node->left,sum,temp); right = dfs(node->right,sum,temp); return left|right; 其中,sum为最终的求和参数,temp为到目

qq_27615887的博客 226

UFAST车道线检测 Ultra-Fast-Lane-Detection 从环境搭建到复现完成(一)

UFAST车道线检测 Ultra-Fast-Lane-Detection 从环境搭建到复现完成(一)

m0_46364958的博客 4345

Leetcode刷题打卡贴,第一次有排名啦,文末附Leetcode刷题路线

种一棵树最好的时间是十年前,其次是现在

qq_53086461的博客 1268

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

[leetcode]大可日常打卡2

804. Unique Morse Code Words    先把所有的字母以及对应的morse code存储到map里面,然后对于words的每一个,把对应的transformation存储到一个hashmap里面,要是里面有对应的转换的话,就continue;没有的话就添加,返回transformation这个map的size就好。import java.util.HashMap; clas...

hellodake的博客 225

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

【LeetCode高频SQL50题-基础版】打卡第1天:第1~10题

在这个博客专栏中,我将为大家提供关于 LeetCode 高频 SQL 题目的基础版解析。LeetCode 是一个非常受欢迎的编程练习平台,其中的 SQL 题目涵盖了各种常见的数据库操作和查询任务。对于计算机科班出身的同学来说,SQL 是一个基础而又重要的技能。不仅在面试过程中经常会遇到 SQL 相关的考题,而且在日常的开发工作中,掌握 SQL 的能力也是必备的。本专栏的目的是帮助读者掌握 LeetCode 上的高频 SQL 题目,并提供对每个题目的解析和解决方案。

热爱编程、热爱生活、热爱探索 1805

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

[leetcode]大可日常打卡-树

687. Longest Univalue Path    一开始非常没有思路。看了解析以后,找到了思路,把长度看作是从一个节点向左右子树延伸出去的两个箭头,如果箭头上的值等于节点的值,那么那么路径的长度就加1。然后刚开始写出的代码分别计算两边的,然后加起来。226. 翻转二叉树    ...

hellodake的博客 224

【LeetCode高频SQL50题-基础版】打卡第4天:第21~25题

在这个博客专栏中,我将为大家提供关于 LeetCode 高频 SQL 题目的基础版解析。LeetCode 是一个非常受欢迎的编程练习平台,其中的 SQL 题目涵盖了各种常见的数据库操作和查询任务。对于计算机科班出身的同学来说,SQL 是一个基础而又重要的技能。不仅在面试过程中经常会遇到 SQL 相关的考题,而且在日常的开发工作中,掌握 SQL 的能力也是必备的。本专栏的目的是帮助读者掌握 LeetCode 上的高频 SQL 题目,并提供对每个题目的解析和解决方案。

热爱编程、热爱生活、热爱探索 749

【LeetCode高频SQL50题-基础版】打卡第7天:第36~40题

在这个博客专栏中,我将为大家提供关于 LeetCode 高频 SQL 题目的基础版解析。LeetCode 是一个非常受欢迎的编程练习平台,其中的 SQL 题目涵盖了各种常见的数据库操作和查询任务。对于计算机科班出身的同学来说,SQL 是一个基础而又重要的技能。不仅在面试过程中经常会遇到 SQL 相关的考题,而且在日常的开发工作中,掌握 SQL 的能力也是必备的。本专栏的目的是帮助读者掌握 LeetCode 上的高频 SQL 题目,并提供对每个题目的解析和解决方案。

热爱编程、热爱生活、热爱探索 923

最长回文串_【Leetcode每日打卡】最长回文串

干货预警:所有文章都会首发于我的公众号【甜姨的奇妙冒险】,欢迎watch。一、来历: 力扣从3月开始开启了每日一题打卡活动,于是跟风加入了打卡大军,这两天写评论、发题解,没想到反响还不错,收到了来自很多同学的鼓励与好评,短短几天就170的关注了,有的同学说每天都会蹲我的评论和题解哈哈 ,本来觉得wx公众号是比较私人的趣味(つд⊂),但不由萌生了在公众号开一个专栏写每日一题的想法,有啥...

weixin_39712455的博客 135

力扣日常打卡面试题04.05.合法二叉搜索树

题目描述: 实现一个函数,检查一颗二叉树是否为搜索树。 示例: 思路及题解: 我们只要弄清楚何为二叉搜索树的概念即可: 即: 左节点的值<根节点的值<右节点的值 且对于左子树与右子树都必须满足这个条件且树内无重复项,简而言之,即: 中序遍历为升序的树才是合法的二叉搜索树。 知道了二叉搜索树的概念后,问题就迎刃而解了。 由于对于任意的子树(包括其本身)都需要满足以上条件,所以直观的思路就是对于每一个子树,我们设定一个lower和upper,若此节点满足 lower<node->val

qq_27615887的博客 278

力扣日常打卡---面试题04.06.后继者

题目描述: 设计一个算法,找出二叉搜索树中指定节点的“下一个”节点(也即中序后继)。 如果指定节点没有对应的“下一个”节点,则返回null。 示例: 思路及题解: 由于题目交代输入树已为二叉搜索树,那么,搜寻后继者的思路就变得清晰。 思路1:用一个vector储存中序遍历的结果,然后找到p所对应的值,则后继者为数组中p的值的后一个值,若p的值为数组中最后一个值,则返回null。代码如下: vector<TreeNode*> temp; void helper(TreeNode* node) {

qq_27615887的博客 335

【LeetCode高频SQL50题-基础版】打卡第8天:第41~45题

在这个博客专栏中,我将为大家提供关于 LeetCode 高频 SQL 题目的基础版解析。LeetCode 是一个非常受欢迎的编程练习平台,其中的 SQL 题目涵盖了各种常见的数据库操作和查询任务。对于计算机科班出身的同学来说,SQL 是一个基础而又重要的技能。不仅在面试过程中经常会遇到 SQL 相关的考题,而且在日常的开发工作中,掌握 SQL 的能力也是必备的。本专栏的目的是帮助读者掌握 LeetCode 上的高频 SQL 题目,并提供对每个题目的解析和解决方案。

热爱编程、热爱生活、热爱探索 856

日常打卡JAVA五道题(1.18)

leetcode 简单题型009回文数解析+代码013罗马数字转整数解析+代码014最长公共前缀解析+代码020有效的括号解析+代码021合并两个有序链表解析+代码 009回文数 解析+代码 class Solution { public boolean isPalindrome(int x) { // 回文数,可以利用StringBuffer的reverse反转函数 // 将n转换为StringBuffer类型 StringBuffer s=new

qq_51517771的博客 450

力扣日常打卡---304.二位区域和检索

题目描述: 给定一个二维矩阵,计算其子矩形范围内元素的总和,该子矩阵的左上角为 (row1, col1) ,右下角为 (row2, col2)。 上图子矩阵左上角 (row1, col1) = (2, 1) ,右下角(row2, col2) = (4, 3),该子矩形内元素的总和为 8。 示例: 说明: 你可以假设矩阵不可变。 会多次调用 sumRegion 方法。 你可以假设 row1 ≤ row2 且 col1 ≤ col2。 思路与题解: 思路1:暴力法 即列举左上角至右下角所有的元素,把他们

qq_27615887的博客 375

力扣日常打卡---面试题04.10.检查子树

题目描述: 检查子树。你有两棵非常大的二叉树:T1,有几万个节点;T2,有几万个节点。设计一个算法,判断 T2 是否为 T1 的子树。 如果 T1 有这么一个节点 n,其子树与 T2 一模一样,则 T2 为 T1 的子树,也就是说,从节点 n 处把树砍断,得到的树与 T2 完全相同。 示例: 思路与题解: 看到题目要求,这种包含关系,第一时间我想的是把二叉树与字符串进行转换,然后判断: return !(s1.find(s2)==string::npos); 其中s1为t1树中序遍历的结果,s2为t2

qq_27615887的博客 407
上一篇: 2感知机
下一篇: [2017校招]大可打卡1
hellodake
博客等级 码龄10年 24粉丝 101原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值