原题链接在这里:https://leetcode.com/problems/the-earliest-moment-when-everyone-become-friends/ 题目: In a social group, there are N people, with unique integer ids from 0 to N-1. We have a list of logs, where each logs[i] = [timestamp, id_A, id_B] contains a…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 并查集 日期 题目地址:https://leetcode-cn.com/problems/the-earliest-moment-when-everyone-become-friends/ 题目描述 In a social group, there are N people, with unique integer ids from 0 to N-1.…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序+并查集 优先级队列 日期 题目地址:https://leetcode-cn.com/problems/path-with-maximum-minimum-value/ 题目描述 Given a matrix of integers A with R rows and C columns, find the maximum score of a p…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 并查集 日期 题目地址:https://leetcode-cn.com/problems/number-of-connected-components-in-an-undirected-graph/ 题目描述 Given n nodes labeled from 0 to n - 1 and a list of undirected edges (ea…
Design a hit counter which counts the number of hits received in the past 5 minutes. Each function accepts a timestamp parameter (in seconds granularity) and you may assume that calls are being made to the system in chronological order (ie, the times…
Write a function to generate the generalized abbreviations of a word. Example: Given word = "word", return the following list (order does not matter): ["word", "1ord", "w1rd", "wo1d", "wor1", &qu…
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive. For example, given the range [5, 7], you should return 4. Credits:Special thanks to @amrsaqr for adding this problem and creatin…
原题链接在这里:https://leetcode.com/problems/counting-bits/ 题目: Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array. Example:For num = 5…
原题链接在这里:https://leetcode.com/problems/design-hit-counter/. 题目: Design a hit counter which counts the number of hits received in the past 5 minutes. Each function accepts a timestamp parameter (in seconds granularity) and you may assume that calls are…
Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary representation. (Recall that the number of set bits an integer has is the number of 1s present when written in bin…
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area. (二)解题 题目大意:给定一个二值矩阵,计算矩阵里面包含1的所有子矩阵的最大面…
这是悦乐书的第311次更新,第332篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第180题(顺位题号是762).给定两个正整数L和R,在[L,R]范围内,计算每个整数的二进制数中1的个数,判断1的个数是否是一个素数.例如,21的二进制数是10101,其中1的个数有3个,3是一个素数.例如: 输入:L = 6,R = 10 输出:4 说明: 6 --> 110(2个1,2是素数) 7 --> 111(3个1,3是素数) 9 --> 1001(2个1,2是素数…
这是悦乐书的第186次更新,第188篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第45题(顺位题号是191).编写一个带无符号整数的函数,并返回它所具有的"1"位数.例如: 输入:11 输出:3 说明:整数11具有二进制表示00000000000000000000000000001011 输入:128 输出:1 说明:整数128具有二进制表示00000000000000000000000010000000 本次解题使用的开发工具是eclipse,jdk使…
每次刷leetcode都有一种发现新大陆的感觉. 题目链接:https://leetcode-cn.com/problems/counting-bits/description/ 给定一个非负整数 num. 对于范围 0 ≤ i ≤ num 中的每个数字 i ,计算其二进制数中的1的数目并将它们作为数组返回. 示例:比如给定 num = 5 ,应该返回 [0,1,1,2,1,2]. 进阶: 给出时间复杂度为O(n * sizeof(integer)) 的解答非常容易. 但是你可以在线性时间O(n…
Implement pow(x, n). Analysis:  Time Complexity: O(LogN) Iterative code: refer to https://discuss.leetcode.com/topic/40546/iterative-log-n-solution-with-clear-explanation N = 9 = 2^3 + 2^0 = 1001 in binary. Then: x^9 = x^(2^3) * x^(2^0) We can see th…
原题链接在这里:https://leetcode.com/problems/friend-circles/description/ 题目: There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direc…
原题链接在这里:https://leetcode.com/problems/design-hit-counter/description/ 题目: Design a hit counter which counts the number of hits received in the past 5 minutes. Each function accepts a timestamp parameter (in seconds granularity) and you may assume tha…
Design a hit counter which counts the number of hits received in the past 5 minutes. Each function accepts a timestamp parameter (in seconds granularity) and you may assume that calls are being made to the system in chronological order (ie, the times…
整数 一.整数反转_7 /* 12345 变成 54321 */ public class 整数反转_7 { public static void main(String[] args){ int x = 12345; System.out.println(reverseInt(x)); } public static int reverseInt(int x){ int res = 0; while (x != 0){ int pop = x % 10; if (res > Integer.M…
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example: Given a = 1 and b = 2, return 3. 转自https://discuss.leetcode.com/topic/49771/java-simple-easy-understand-solution-with-explanation/2,注意里面对于减法的讲解 h…
LeetCode题解: LRU Cache 缓存设计 2014年12月10日 08:54:16 邴越 阅读数 1101更多 分类专栏: LeetCode   版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/leread/article/details/41841965 设计并实现最近最久未使用(Least Recently Used)缓存. 链接:https://oj.leetcode.c…
First. 陈列一下“异或”的一些性质 异或是一种基于二进制的位运算,用符号XOR或者 ^ 表示,其运算法则是对运算符两侧数的每一个二进制位,同值取0,异值取1. 它与布尔运算的区别在于,当运算符两侧均为1时,布尔运算的结果为1,异或运算的结果为0. 性质 1.交换律 2.结合律(即(a^b)^c == a^(b^c)) 3.对于任何数x,都有x^x=0,x^0=x 4.自反性 A ^ B ^ B = A ^  0 = A  应用 一.交换两个整数的值而不必用第三个参数 a = 9; b =…
leetcode -- 二进制 在学习编程语言的运算符时,大部分语言都会有与,或等二进制运算符,我在初期学习这些运算符的时候,并没有重点留意这些运算符,并且在后续的业务代码中也没有频繁的使用过,直到后来的一些算法题目和源码中经常遇到它们的身影,这些二进制运算符相比普通的运算符具有更快的效率,比如hashMap的源码就是将%替换成了&.我们在日常的很多需求都是可以转化为二进制运算符来完成的,这篇文章整理我在刷leetcode的时候遇到的一些二进制题目,对于很多问题,其实我们是没有意识来用这些二进制…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 转成十进制模拟 修改二进制字符串 日期 题目地址:https://leetcode-cn.com/problems/number-of-steps-to-reduce-a-number-in-binary-representation-to-one/ 题目描述 给你一个以二进制形式表示的数字 s .请你返回按下述规则将其减少到 1 所需要的步骤数: 如…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历数字+质数判断 日期 题目地址:https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation/description/ 题目描述 Given two integers L and R, find the count of numbers in the…
# 增强学习成果 有一个研究成果,在学习中传授他人知识和讨论是最高效的做法,而看书则是最低效的做法(具体研究成果没找到地址).我写LeetCode博客主要目的是增强学习成果.当然,我也想出名,然而不知道能否出名. # 给算法的新手们提供一种思考方式的参考 提前说明,本人也不是高手. 算法这个东西有点玄乎.很多新手(包括我)初期入门的时候都学的是<算法导论>,然而我并不觉得<算法导论>是一本学习算法很好的书. 我们设计算法的流程,并不是像<算法导论>那样,好像天生就知道这…
终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance 44.10% Meidum 475 Heaters  30.20% Easy 474 Ones and Zeroes  34.90% Meidum 473 Matchsticks to Square  31.80% Medium 472 Concatenated Words 29.20% Hard…
Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times. Example 1: Input: s = "aaabb", k = 3 Output: 3 The longest substring is "aaa"…
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1 return [ [5,4,11,2],…
题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11…