problem 933. Number of Recent Calls 参考 1. Leetcode_easy_933. Number of Recent Calls; 完…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 二分查找 队列 相似题目 参考资料 日期 题目地址:https://leetcode.com/problems/number-of-recent-calls/description/ 题目描述 Write a class RecentCounter to count recent requests. It has only one method: p…
Write a class RecentCounter to count recent requests. It has only one method: ping(int t), where t represents some time in milliseconds. Return the number of pings that have been made from 3000 milliseconds ago until now. Any ping with time in [t - 3…
problem 1128. Number of Equivalent Domino Pairs solution1: 不明白为什么每个元素都要加上count: class Solution { public: int numEquivDominoPairs(vector<vector<int>>& dominoes) { ; unordered_map<int, int> count; for(auto d:dominoes) { res += count[mi…
problem 806. Number of Lines To Write String solution: class Solution { public: vector<int> numberOfLines(vector<int>& widths, string S) { , len = ; for(auto ch:S) { int t = widths[ch-'a']; ) line++; len = (len+t>) ? t : len+t; } return…
[POJ2104][HDU2665]K-th Number Description You are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structure that would be able to return quickly k-th…
[SPOJ]NUMOFPAL - Number of Palindromes(Manacher,回文树) 题面 洛谷 求一个串中包含几个回文串 题解 Manacher傻逼题 只是用回文树写写而已.. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<…
[LeetCode]Largest Number 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/largest-number/#/description 题目描述: Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], t…
[LeetCode]792. Number of Matching Subsequences 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/number-of-matching-subsequences/description/ 题目描述: Given string S and a dictionary of words words,…
[LeetCode]673. Number of Longest Increasing Subsequence 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/number-of-longest-increasing-subsequence/description/ 题目描述: Given an unsorted array of integers, find the number of longest inc…
Single Number I : Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Solution: 解法不少,贴一种: class…
The Number of Palindromes Problem Description Now, you are given a string S. We want to know how many distinct substring of S which is palindrome. Input The first line of the input contains a single integer T(T<=20), which indicates number of test ca…
题目描述: 给定一个数组,里面除了一个数字,其他的都出现三次.求出这个数字 原文描述: Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra m…
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 任何一个整数N都能表示成另外两个整数a和b的平方差吗?如果能,那么这个数N就叫做Couple number.你的工作就是判断一个数N是不是Couple number. [输入格式] 仅一行,两个长整型范围内的整数n1和n2,之间用1个空格隔开. [输出格式] 输出在n1到n2范围内有多少个Couple number. 注意:包括n1和n2两个数,且n1<n2,n2 -="" n1=&…
这是悦乐书的第357次更新,第384篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第219题(顺位题号是933).写一个类RecentCounter来计算最近的请求. 它只有一个方法:ping(int t),其中t代表一些时间(以毫秒为单位). 返回从3000毫秒前到现在为止的ping数. 在[t-3000,t]中任何时间ping都将计数,包括当前ping. 每次调用ping都使用比之前严格更大的t值.例如: 输入:inputs = ["RecentCounter&…
problem 1137. N-th Tribonacci Number solution: class Solution { public: int tribonacci(int n) { ) ; || n==) ; , t1 = , t2 = , t3 = ; ; i<=n; i++) { t3 = t0+t1+t2; t0 = t1; t1 = t2; t2 = t3; } return t3; } };     参考 1. Leetcode_easy_1137. N-th Tribona…
problem 762. Prime Number of Set Bits in Binary Representation solution1: class Solution { public: int countPrimeSetBits(int L, int R) { int res = 0; int bits = 0; for(int i=L; i<=R; i++) { bits = countBits(i); if(isPrime(bits) && bits!=1 ) res…
problem 754. Reach a Number solution1: class Solution { public: int reachNumber(int target) { target = abs(target); +8.0*target)-1.0)); )/; if(sum==target) return n; long d = sum - target; ) == ) return n; ) ? : ); } }; solution2: class Solution { pu…
problem 747. Largest Number At Least Twice of Others 题意: solution1: class Solution { public: int dominantIndex(vector<int>& nums) { , secondMx = -, mxId = -;//err... ) ; ; i<nums.size(); i++) { if(nums[i]>mx) { secondMx = mx; mx = nums[i];…
problem 693. Binary Number with Alternating Bits solution1: class Solution { public: bool hasAlternatingBits(int n) { ; ) { /* errr... if(n&1 && bit==1) return false; else if(n&1) bit = 1; if(n&1==0 && bit==0) return false; els…
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4134 访问. 写一个 RecentCounter 类来计算最近的请求. 它只有一个方法:ping(int t),其中 t 代表以毫秒为单位的某个时间. 返回从 3000 毫秒前到现在的 ping 数. 任何处于 [t - 3000, t] 时间范围之内的 ping 都将会被计算在内,包括当前(指 t 时刻)的 ping. 保证每次对 ping 的调用都使用比之前…
Write a class RecentCounter to count recent requests. It has only one method: ping(int t), where t represents some time in milliseconds. Return the number of pings that have been made from 3000 milliseconds ago until now. Any ping with time in [t - 3…
Write a class RecentCounter to count recent requests. It has only one method: ping(int t), where t represents some time in milliseconds. Return the number of pings that have been made from 3000 milliseconds ago until now. Any ping with time in [t - 3…
Write a class RecentCounter to count recent requests. It has only one method: ping(int t), where t represents some time in milliseconds. Return the number of pings that have been made from 3000 milliseconds ago until now. Any ping with time in [t - 3…
题目描述: 给定一个数组,里面只有两个数组,只是出现一次,其余的数字都是出现两次,找出这个两个数字,数组形式输出 原文描述: Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. For example: G…
题目如下: (This problem is an interactive problem.) On the sea represented by a cartesian plane, each ship is located at an integer point, and each integer point may contain at most 1 ship. You have a function Sea.hasShips(topRight, bottomLeft) which tak…
题目简述 Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process unti…
题目简述: Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330. Note: The result may be very large, so you need to return a string instead o…
简单题 Ugly Number My Submissions Question Total Accepted: 32635 Total Submissions: 94009 Difficulty: Easy Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For…
Valid Number Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => true Note: It is intended for the problem statement to be am…