1018. Binary Prefix Divisible By 5可被 5 整除的二进制前缀
网址:https://leetcode.com/problems/binary-prefix-divisible-by-5/
一次for循环遍历数组,在上次计算的基础上得到本次的结果!
class Solution {
public:
vector<bool> prefixesDivBy5(vector<int>& A)
{
vector<bool> ans;
int num = ;
int pre_num = ;
for(int i=; i<A.size(); i++)
{
num = ;
num += pre_num * + A[i];
num = num % ;
pre_num = num;
if(num % == )
{
ans.push_back(true);
}
else
ans.push_back(false);
}
return ans;
}
};
1018. Binary Prefix Divisible By 5可被 5 整除的二进制前缀的更多相关文章
- 【LeetCode】1018. Binary Prefix Divisible By 5 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【leetcode】1018. Binary Prefix Divisible By 5
题目如下: Given an array A of 0s and 1s, consider N_i: the i-th subarray from A[0] to A[i] interpreted a ...
- Leetcode 1018. Binary Prefix Divisible By 5
class Solution: def prefixesDivBy5(self, A: List[int]) -> List[bool]: ans,t = [],0 for a in A: t ...
- [Swift]LeetCode1018. 可被 5 整除的二进制前缀 | Binary Prefix Divisible By 5
Given an array A of 0s and 1s, consider N_i: the i-th subarray from A[0] to A[i] interpreted as a bi ...
- Binary Prefix Divisible By 5 LT1018
Given an array A of 0s and 1s, consider N_i: the i-th subarray from A[0] to A[i] interpreted as a bi ...
- LeetCode.1018-可被5整除的二进制数(Binary Prefix Divisible By 5)
这是小川的第379次更新,第407篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第241题(顺位题号是1018).给定0和1的数组A,考虑N_i:从A[0]到A[i]的第 ...
- CJOJ 1976 二叉苹果树 / URAL 1018 Binary Apple Tree(树型动态规划)
CJOJ 1976 二叉苹果树 / URAL 1018 Binary Apple Tree(树型动态规划) Description 有一棵苹果树,如果树枝有分叉,一定是分2叉(就是说没有只有1个儿子的 ...
- timus 1018. Binary Apple Tree
1018. Binary Apple Tree Time limit: 1.0 secondMemory limit: 64 MB Let's imagine how apple tree looks ...
- URAL 1018 Binary Apple Tree(树DP)
Let's imagine how apple tree looks in binary computer world. You're right, it looks just like a bina ...
随机推荐
- C#基础加强(2)之密闭类、静态类及扩展方法
密闭类 简介 密闭类是被 sealed 关键字修饰的类,密闭类不能有子类.一般只有系统的一些基本类声明为密闭类,例如 String 类. 相关面试题 是否可以编写一个类继承自 String 类? 我们 ...
- int bool 字符串 列表 字典 集合
1.int和bool 输出i的最大二进制位数inti = 1000 print(i.bit_length()) 2. str int bool list set dict tuple 相互转换 pr ...
- 9个用来爬取网络站点的 Python 库
上期入口:10个不到500行代码的超牛Python练手项目 1️⃣Scrapy 一个开源和协作框架,用于从网站中提取所需的数据. 以快速,简单,可扩展的方式. 官网:https://scrapy.or ...
- python基础语法及知识点总结
本文转载于星过无痕的博客http://www.cnblogs.com/linxiangpeng/p/6403991.html 在此表达对原创作者的感激之情,多谢星过无痕的分享!谢谢! Python学习 ...
- 关于NFS服务器权限的四种情况
第一种:service 和client 的UID和用户名一样 client按照service端的权限来使用.
- py-faster-rcnn
踩坑: 1. 服务器上训练: sh ./experiments/scripts/faster_rcnn_end2end.sh 会各种报错 有说是因为#!/bin/bash的问题,改过,不行. 改成如下 ...
- Unable to construct api.Node object for kubelet: can't get ip address of node master.example.com: lookup master.example.com on : no such host
openshift首页进不去 启动openshift时报的错,大意是: 无法为kubelet构造api.Node对象:无法获取节点master.example.com的IP地址: 所以就联想到新装的c ...
- 4A Watermelon
A. Watermelon time limit per test 1 second memory limit per test 64 megabytes input standard input o ...
- 2、Kafka架构
Kafka架构图 1)Producer :消息生产者,就是向kafka broker发消息的客户端. 2)Consumer :消息消费者,向kafka broker取消息的客户端 3)Topic :可 ...
- centos etcd 启动失败
chmod -R 777 /var/lib/etcd systemctl daemon-reload cat /etc/systemd/system/etcd.service " [Unit ...