412. Fizz Buzz

leetcode:412.Fizz Buzz 题目 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/fizz-buzz 给你一个整数 n ,找出从 1 到 n 各个整数的 Fizz Buzz 表示,并用字符串数组 answer(下标从 1 开始)返回结果,其中: answer[i] == “FizzBuzz” 如果 i 同时是 3 和 5 的倍数。 answer[i] == “Fizz” 如果 i 是 3 的倍数。 answer[i] == “Buzz” 如果 i 是 5 的倍数。 answer 阅读详情

直接判断每个整数能否被3或者5整除:

class Solution {
public:
    vector<string> fizzBuzz(int n) {
        vector<string> res;
        for(int i=1;i<=n;i++)
        {
            if(i%3==0&&i%5!=0)
                res.push_back("Fizz");
            else
                if(i%3!=0&&i%5==0)
                    res.push_back("Buzz");
            else
                if(i%3==0&&i%5==0)
                    res.push_back("FizzBuzz");
            else
                res.push_back(to_string(i));
                    
        }
        return res;
    }
};

 

Leetcode 412. Fizz Buzz-蜂鸣器 Leetcode 412. Fizz Buzz-蜂鸣器;Given an integern, returna string arrayanswer(1-indexed) where: answer[i] == "FizzBuzz"ifiis divisible by3and5. answer[i] == "Fizz"ifiis divisible by3. answer[i] == "Buzz"ifiis divisible by5. answer[i] == i(a 阅读详情

相关推荐

Dify保姆级教程:从零搭建AI知识库,让大模型真正懂你的文档

通用大模型的知识边界来自公开语料,面对企业内部制度、产品手册等私有内容,往往只能靠“猜”,由此产生幻觉。要解决这个问题,需要借助检索增强生成(RAG)技术,为模型配置一个外挂资料库。RAG的原理类似开卷考试:先对文档进行文本切分、向量化,再在提问时检索语义相关的片段,交由大模型生成答案。Dify作为开源AI知识库平台,将文档导入、分段设置、向量索引、召回测试等复杂链路封装成可视化操作,让产品经理、运营等非研发人员也能独立搭建企业级问答助手。本文从环境部署、模型接入、参数调优到多知识库维护,完整覆盖一条可落地

weixin_29039773的博客 221

leetcode412. Fizz Buzz,简单遍历

leetcode412. Fizz Buzz,简单遍历

热爱C++和golang的学生 1370

从零构建C++ Gerber解析器:以PCB缺陷检测为目标的实战指南

本文是一份面向PCB缺陷检测项目的实战指南,详细介绍了如何从零开始使用C++构建高性能的Gerber文件解析器。文章深入剖析了Gerber RS-274X格式,并提供了完整的开发环境搭建、核心数据结构设计、解析步骤实现以及为缺陷检测优化的具体方案,旨在帮助开发者获得对PCB制造数据的深度控制与极致性能。

weixin_29291185的博客 184

LeetCode 412 - Fizz Buzz

这道题其实是很多人入门算法时的经典“Hello World”级别的逻辑题——Fizz Buzz。它看起来很简单,但却经常被面试官用来考察你对逻辑判断、代码结构清晰度以及边界条件处理的习惯。 在这篇文章里,我们会从实际开发的思维出发,聊聊怎么用 Swift 实现一个干净、清晰、可扩展的 Fizz Buzz,同时结合一些真实的使用场景,比如日志输出、系统监控状态显示等,帮你理解这类“规则映射”的问题其实在工程里非常常见。

记录从移动端、鸿蒙到物联网与AI的完整实战与思考。专注于分享可复用的工程方案与产品思维,尤其深入鸿蒙生态与全栈开发。以十年工程与管理沉淀,为你提供清晰的技术纵深路径。坚信技术的价值在于“贯通”与“落地”。 644

OpenIddict实战指南:在.NET Core中构建安全的OAuth 2.0与OpenID Connect服务

本文详细介绍了如何在.NET Core中使用OpenIddict框架构建安全、标准的OAuth 2.0与OpenID Connect授权服务。内容涵盖从快速搭建授权服务器、理解核心配置与授权流程,到集成用户数据库、实现完整登录授权,以及生产环境下的安全加固与部署指南,为.NET开发者提供了一套现代、可维护的认证授权解决方案。

weixin_29229989的博客 355

VoLTE吞字断续优化方案

网络侧通过各节点探针的数据采集,能够进行RTP和RTCP包的分析,确定各节点的上行或下行丢包情况。1.基于测试语音分析,每2秒中大约8个字,每个字约10个RTP语音包。通话过程中,语音有短暂停顿,收音段听语音中会出现“吞字/断续现象”2.连续丢3~5个RTP以上就可能会出现吞字断续的感觉。下行评价的丢包问题,很难有效指导定界定位分析,无从下手。2.部分终端可能存在RTCP不反馈,导致无法获取丢包。1.语音包为UDP包,无反馈,终端无法判定是否丢包。终端可依据自身的调度反馈或弃包进行上行丢包判决。

m0_73503557的博客 1515

LeetCode 412 Fizz Buzz(JAVA)

class Solution { public List<String> fizzBuzz(int n) { List<String> res = new ArrayList<>(n); for (int i = 1; i <= n; i++) { // 首先判断能否被3/5整除 if (i % 3 == 0 && i % 5 == 0) { .

weixin_43170297的博客 376

【WRF-Urban】Registry.EM_COMMON文件概述及urban有关变量

Registry.EM_COMMON文件概述及urban有关变量

WW、forever的博客 1596

Java实现 LeetCode 412 Fizz Buzz

412. Fizz Buzz 写一个程序,输出从 1 到 n 数字的字符串表示。 如果 n 是3的倍数,输出“Fizz”; 如果 n 是5的倍数,输出“Buzz”; 3.如果 n 同时是3和5的倍数,输出 “FizzBuzz”。 示例: n = 15, 返回: [ "1", "2", "Fizz", "4", "Buzz", "Fizz"...

南 墙 1万+

Halcon那些事:Halcon缺陷检测检测印刷数字完整性

创建模板 create_shape_model模板匹配 find_shape_model。

十多年IT经验,专注机器视觉,智能制造半导体行业 769

手把手教你用ESP32-C3打造智能聊天机器人-立创实战派

本文将详细介绍如何利用立创ESP32-C3开发板,烧录小智AI程序,快速实现一个功能强大的聊天机器人。

举世誉之而不加劝,举世非之而不加沮,定乎内外之分,辩乎荣辱之境,斯已矣。 5544

LeetCode //C - 412. Fizz Buzz

【代码】LeetCode //C - 412. Fizz Buzz。

Made in Code 965

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

LeetCode 412 Fizz Buzz Java实现

LeetCode412 题目 写一个程序,输出从 1 到 n 数字的字符串表示。 如果 n 是3的倍数,输出“Fizz”; 如果 n 是5的倍数,输出“Buzz”; 3.如果 n 同时是3和5的倍数,输出 “FizzBuzz”。 示例: n = 15, 返回: [ “1”, “2”, “Fizz”, “4”, “Buzz”, “Fizz”, “7”, “8”, “Fizz”, “Buzz”, “11”, “Fizz”, “13”, “14”, “FizzBuzz” ] 通过次数45,972提交

BedivereAlter的博客 398

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

LeetCode412. Fizz Buzz

412. Fizz Buzz class Solution { public: //时间:O(n), 空间: O(1) vector<string> fizzBuzz(int n) { if(n <= 0) return {}; vector<string> ans(n); for(int i = 1; i <= n; i++) { if(i % 3 == 0 && i

oykotxuyang的博客 127

深度学习工具包 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 412 Fizz Buzz

Leetcode 412 Fizz Buzz#include <vector> #include <string> using namespace std;class Solution { public: vector<string> fizzBuzz(int n) { vector<string> fizzbuzz; for(int i = 1;i <= n;i +

自己的学习笔记 394

leetcode-412- Fizz Buzz

问题题目:[leetcode-412]思路枚举判断。代码/* 3 : Fizz 5:Buzz 3&&5FizzBuzz */class Solution { public: vector<string> fizzBuzz(int n) { std::vector<std::string> ret; for( int i = 1; i <= n; ++i )

Kang_TJU的博客 564

leetcode 412. Fizz Buzz

【题目】412. Fizz Buzz 写一个程序,输出从 1 到 n 数字的字符串表示。 如果 n 是3的倍数,输出“Fizz”; 如果 n 是5的倍数,输出“Buzz”; 如果 n 同时是3和5的倍数,输出 “FizzBuzz”。 示例: n = 15, 返回: [ "1", "2", "Fizz", "4", "Buzz", "Fizz",...

Sophia_fez的博客 364

【LeetCode笔记】412. Fizz Buzz

题目 写一个程序,输出从 1 到 n 数字的字符串表示。 如果 n 是3的倍数,输出“Fizz”; 如果 n 是5的倍数,输出“Buzz”; 如果 n 同时是3和5的倍数,输出 “FizzBuzz”。 示例:n = 15, 返回: [ "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13",

Sherry_LiuYJ的博客 389

每日一题 412. Fizz Buzz

【代码】每日一题 412. Fizz Buzz。

qq_42376925的博客 230

【leetcode】412.Fizz Buzz (三种方法开阔思路,java实现)

412. Fizz Buzz 难度简单 写一个程序,输出从 1 到 n 数字的字符串表示。 如果 n 是3的倍数,输出“Fizz”; 如果 n 是5的倍数,输出“Buzz” 如果 n 同时是3和5的倍数,输出 “FizzBuzz”。 示例: n = 15, 返回: [ "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11

Viper的程序员修炼手册 3039

python-leetcode-412. Fizz Buzz

如果有更优化的需求,或者需要其他语言的实现,欢迎交流!

Lucy_wzw的博客 310

【LeetCode】412. Fizz Buzz

【LeetCode】412. Fizz Buzz 题目: Write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of the number and for the multipl...

A_Huiii的博客 171

面试必考的最简单逻辑题——力扣412.Fizz Buzz

题目要求对1到n的每个数字按特定规则转换为字符串:3的倍数输出"Fizz",5的倍数输出"Buzz",同时是3和5的倍数输出"FizzBuzz",否则输出数字本身。通过遍历1到n,使用条件判断依次处理这些情况即可。Java实现时需要注意判断顺序,先检查3和5的共同倍数。时间复杂度O(n),空间复杂度O(1)。该题考察基础循环和条件判断能力,通过字符串拼接可以优化代码结构。

w1311823723的博客 401
上一篇: 476. Number Complement
下一篇: 661. Image Smoother
云水谣CS
博客等级 码龄9年 8粉丝 268原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值