随笔分类 - Online Judge
摘要:References: 1. Stanford University CS97SI by Jaehyun Park 2. Introduction to Algorithms 3. Kuangbin's ACM Template 4. Data Structures by Dayou Liu 5.
阅读全文
摘要:1. 思路 这题实际上是个几何问题——两个外相切的圆,由勾股定理,他们的纵坐标有以下的规律: 则有$$y_{n+1} = y_{n} + \sqrt{(2r)^2 - (x_{n} - x_{n+1})^2}$$ 其中x代表横坐标,y代表纵坐标,r代表半径。 简略画了个图: 2. 容易错的地方 非常
阅读全文
摘要:1. 题目描述Description Link: https://leetcode.com/problems/majority-element/description/ Given an array of size n, find the majority element. The majority
阅读全文
摘要:1) Link to the problem: http://codeforces.com/contest/888/problem/C 2) Description: You are given a string s consisting of lowercase Latin letters. Ch
阅读全文
摘要:1. 问题 231. Power of Two: 判断一个整数是否是2的n次方,其中n是非负整数 342. Power of Four: 判断一个整数是否是4的n次方,其中n是非负整数 326. Power of Three: 判断一个整数是否是3的n次方,其中n是非负整数 2. 思路 1)2的n次
阅读全文
摘要:1. 题目:https://leetcode.com/problems/reverse-words-in-a-string-iii/discuss/ 反转字符串中的所有单词。 2. 思路: 这题主要是要注意空格的影响。比方说,string首尾和单词之间可能有一或多个空格。看到有人逐个对空格判断,但是
阅读全文
摘要:1. 题目链接:https://leetcode.com/problems/hamming-distance/description/ 2.思路 常规做法做完看到评论区一个非常有意思的做法。用了n&=(n-1),这个地方的意思是,将最右边的1变成0。比方说: 最简单的例子: 原数字: 101011
阅读全文
摘要:1. 题目大意 根据给定矩阵,重塑一个矩阵,r是所求矩阵的行数,c是所求矩阵的列数。如果给定矩阵和所求矩阵的数据个数不一样,那么返回原矩阵。否则,重塑矩阵。其中两个矩阵中的数据顺序不变(先行后列)。 2. 思路 由于矩阵中数据顺序不变,因此我们考虑按顺序做。原矩阵中的第i行第j列(从0开始)的数据可
阅读全文
摘要:原题 [原题链接][1] Description: Count the number of prime numbers less than a non negative number, n. 计算小于非负数n的素数个数。 思路 这题用[埃拉托斯特尼筛法][2]来做效果比较好,普通的方法基本会TLE。
阅读全文
摘要:原题 [原题链接][1] You are given a map in form of a two dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected ho
阅读全文
摘要:题目 [题目链接][1] Given a non empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring togeth
阅读全文
摘要:题目 [题目链接][1] Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements th
阅读全文
摘要:1.题目:原题链接 Given an integer, write a function to determine if it is a power of two. 给定一个整数,判断该整数是否是2的n次幂。 2.思路 如果一个整数是2的n次幂,那么首先其应当是正数,其次该数的二进制表示必定是以1开
阅读全文
摘要:1.题目大意 Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. For examp
阅读全文
摘要:1.题目: 原题:Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. Subscribe to see which companies
阅读全文
摘要:1.题目大意 Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one more let
阅读全文
摘要:1.题目大意 A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements
阅读全文
摘要:1.题目大意 Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The f
阅读全文
摘要:1.题目大意 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 th
阅读全文
摘要:1.题目大意 Given an array of integers, every element appears twice except for one. Find that single one. Note:Your algorithm should have a linear runtime
阅读全文

浙公网安备 33010602011771号