
每周一算
每周一道算法题
无良剑染
这个作者很懒,什么都没留下…
展开
-
【算法】Longest Substring Without Repeating Characters 最长无重复字符子串
【算法】Longest Substring Without Repeating Characters 最长无重复字符子串题目解题思路代码实现题目Given a string, find the length of the longest substring without repeating characters.Example 1:Input: “abcabcbb”Output: 3...原创 2020-04-22 19:19:16 · 322 阅读 · 0 评论 -
【算法】Nth Magical Number 第N个神奇数字
【算法】Nth Magical Number 第N个神奇数字题目解题思路代码实现题目A positive integer is magical if it is divisible by either A or B.Return the N-th magical number. Since the answer may be very large, return it modulo 10^...原创 2020-04-07 22:08:49 · 411 阅读 · 0 评论 -
【算法】Self Crossing 自我相交
【算法】Self Crossing 自我相交题目解题思路代码实现题目You are given an array x of n positive numbers. You start at point (0,0) and moves x[0] metres to the north, then x[1] metres to the west, x[2] metres to the south,...原创 2020-03-30 12:54:22 · 830 阅读 · 0 评论 -
【算法】Best Time to Buy and Sell Stock IV 交易股票嘴角时机4
【算法】Best Time to Buy and Sell Stock IV 交易股票嘴角时机4题目解题思路代码实现题目Say you have an array for which the i-th element is the price of a given stock on day i.Design an algorithm to find the maximum profit. Y...原创 2020-03-23 21:23:15 · 263 阅读 · 0 评论 -
【算法】Longest Valid Parentheses 最长有效括号
【算法】Longest Valid Parentheses 最长有效括号题目解题思路代码实现题目Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.Example 1:Input:...原创 2020-03-18 12:43:43 · 211 阅读 · 0 评论 -
【算法】Create Maximum Number 创建最大数
【算法】Create Maximum Number 创建最大数题目解题思路代码实现题目Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k <= m + n from digits of the two. The ...原创 2020-03-10 18:16:59 · 416 阅读 · 0 评论 -
【算法】Regular Expression Matching 正则匹配
【算法】Regular Expression Matching 正则匹配题目解题思路代码实现题目Given an input string ( s ) and a pattern ( p ), implement regular expression matching with support for ‘.’ and ‘*’.‘.’ Matches any single character....原创 2020-03-03 10:59:07 · 305 阅读 · 0 评论 -
【算法】Super Egg Drop 鸡蛋掉落
【算法】Super Egg Drop 鸡蛋掉落题目解题思路代码实现题目You are given K eggs, and you have access to a building with N floors from 1 to N.Each egg is identical in function, and if an egg breaks, you cannot drop it agai...原创 2020-02-27 07:52:16 · 669 阅读 · 0 评论 -
【算法】Decode Ways II 解码方式2
【算法】Decode Ways II 解码方式2题目解题思路代码实现题目A message containing letters from A-Z is being encoded to numbers using the following mapping way:‘A’ -> 1‘B’ -> 2…‘Z’ -> 26Beyond that, now the enc...原创 2020-02-22 17:55:45 · 276 阅读 · 0 评论 -
【算法】Split Array With Same Average 拆分数组为两个平均值的子数组
【算法】Split Array With Same Average 拆分数组为两个平均值的子数组题目解题思路代码实现题目In a given integer array A, we must move every element of A to either list B or list C. (B and C initially start empty.)Return true if an...原创 2020-02-15 17:32:55 · 513 阅读 · 0 评论 -
【算法】Integer to English Words 数字转换单词
【算法】Integer to English Words 数字转换单词题目解题思路代码实现题目Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 2^31 - 1.Example 1:Input: 123Output: “...原创 2020-02-06 00:17:42 · 382 阅读 · 0 评论 -
【算法】Text Justification 文本对齐
【算法】Text Justification 文本对齐题目解题思路代码实现题目Given an array of words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully (left and right) justified.You ...原创 2020-01-24 21:25:24 · 262 阅读 · 0 评论 -
【算法】Substring with Concatenation of All Words 所有单词链接而成的子串
【算法】Substring with Concatenation of All Words 所有单词链接而成的子串题目解题思路代码实现题目You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s)...原创 2020-01-23 12:02:25 · 196 阅读 · 0 评论 -
【算法】Shortest Subarray with Sum at Least K 求数组中区间和大于等于 K 的最小子数组长度
【算法】Shortest Subarray with Sum at Least K题目解题思路代码实现题目Return the length of the shortest, non-empty, contiguous subarray of A with sum at least K.If there is no non-empty subarray with sum at least K...原创 2020-01-06 15:55:29 · 519 阅读 · 0 评论 -
【算法】Reverse Pairs 翻转对,BIT 解法
文章目录题目解题思路代码实现题目Given an array nums, we call (i, j) an important reverse pair if i < j and nums[i] > 2*nums[j].You need to return the number of important reverse pairs in the given array.Exa...原创 2019-12-31 11:55:48 · 487 阅读 · 0 评论 -
【算法】Reverse Pairs 翻转对,merge sort 解法
文章目录题目解题思路代码实现题目Given an array nums, we call (i, j) an important reverse pair if i < j and nums[i] > 2*nums[j].You need to return the number of important reverse pairs in the given array.Exa...原创 2019-12-26 12:05:46 · 395 阅读 · 0 评论 -
【算法】Wildcard Matching通配符匹配
文章目录题目解题思路代码实现题目Given an input string (s) and a pattern §, implement wildcard pattern matching with support for ‘?’ and ‘*’.‘?’ Matches any single character.‘*’ Matches any sequence of characters ...原创 2019-12-18 22:19:31 · 406 阅读 · 0 评论 -
【算法】Strong Password Checker 强密码检查
文章目录题目解题思路代码实现题目A password is considered strong if below conditions are all met:It has at least 6 characters and at most 20 characters.It must contain at least one lowercase letter, at least one u...原创 2019-12-11 21:27:41 · 934 阅读 · 0 评论 -
【算法】Palindrome Partitioning III 回文分区3
题目You are given a string s containing lowercase letters and an integer k. You need to :First, change some characters of s to other lowercase English letters.Then divide s into k non-empty disjoint ...原创 2019-12-08 21:32:46 · 190 阅读 · 0 评论 -
【算法】Number of Ways to Stay in the Same Place After Some Steps 有多少种移动一定步数后留在原位置的路径
Number of Ways to Stay in the Same Place After Some Steps 有多少种移动一定步数后留在原位置的路径文章目录Number of Ways to Stay in the Same Place After Some Steps 有多少种移动一定步数后留在原位置的路径题目解题思路代码实现题目ou have a pointer at index ...原创 2019-11-27 21:21:30 · 465 阅读 · 0 评论 -
【算法】Word Ladder II单词接龙
文章目录Word Ladder II 寻找字梯题目解题思路代码实现Word Ladder II 寻找字梯题目Given two words (beginWord and endWord), and a dictionary’s word list, find all shortest transformation sequence(s) from beginWord to endWord, ...原创 2019-11-21 23:53:21 · 192 阅读 · 0 评论 -
【算法】Find the Closest Palindrome 寻找最近的较小回数
文章目录Longest Duplicate Substring 最长重复子串题目解题思路代码实现Longest Duplicate Substring 最长重复子串题目Given an integer n, find the closest integer (not including itself), which is a palindrome.The ‘closest’ is defi...原创 2019-11-12 19:24:01 · 251 阅读 · 1 评论 -
【算法】Longest Duplicate Substring 最长重复子串
文章目录Longest Duplicate Substring 最长重复子串题目解题思路代码实现Longest Duplicate Substring 最长重复子串题目给出一个字符串,得出该字符串的最长重复字串,如 “abcabcabc” 的最长重复字串,是 “abcabc”解题思路通过Rabin-Karp算法,可以加速字符串比对简单来说,就是将每个字符映射为一个数值然后设计一个...原创 2019-11-06 23:24:24 · 417 阅读 · 0 评论 -
【算法】Max Points On A Line 坐标系中一条直线上的最多点数
文章目录Max Points On A Line 坐标系中一条直线上的最多点数题目解题思路代码实现Max Points On A Line 坐标系中一条直线上的最多点数题目给出一组坐标系的点,求出能连成一条直线的最多点数解题思路将坐标点 p1 的 x1 与 y1 的值,依次与后面的坐标点 pn的 xn 与 yn 做差值并相除((x1 - xn) / (y1 - yn))得出两点之间的斜...原创 2019-10-31 23:15:36 · 374 阅读 · 0 评论 -
【算法】Valid Number 有效数字
文章目录Valid Number 有效数字题目解题思路代码实现Valid Number 有效数字题目给出一个数字的字符串,可以是科学记数,其中 “3. “、 " .3”、”+.8"也算是正确记数“0” => true" 0.1 " => true“abc” => false“1 a” => false“2e10” => true" -90e3 "...原创 2019-10-24 20:42:37 · 867 阅读 · 0 评论 -
【算法】GCJ2019 Cryptopangrams
这里写自定义目录标题GCJ2019 Cryptopangrams题目:解题思路实现代码GCJ2019 Cryptopangrams题目:出题人随机选了26个不超过N的素数,按照从小到大排列,把每个素数分给起对应的字母,得到了一个由大写字母到这26个素数的一个bijection。然后出题人通过这个bijection对一段message加密,加密过程为(1)把每个字符替换成其对应的素数,得到一...原创 2019-10-17 22:54:16 · 271 阅读 · 0 评论 -
【算法】元素重复三次的数组中查找重复一次的元素
元素重复三次的数组中查找重复一次的元素文章目录元素重复三次的数组中查找重复一次的元素题目:解题思路实现代码题目:给定一个大数组,它里面除了一个元素外,其他元素都重复了三次,要求在空间复杂度为O(1), **时间复杂度为O(n)**的约束下,查找到只重复了一次的元素。意思就是说:这意味着算法必须对数组遍历1次就要找出给定元素。解题思路参考位图算法,声明两个变量 firstAppear...原创 2019-10-09 20:19:06 · 1062 阅读 · 0 评论