![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
渣渣琪
菜鸟成长记
展开
-
Leet Code OJ 22. Generate Parentheses-python
题目:22.Generate ParenthesesMedium5731287Add to ListShareGivennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is:[ "((()))", "(()())", "(())()", ...原创 2020-09-01 20:14:58 · 317 阅读 · 0 评论 -
Leet Code OJ 13. Roman to Integer-python
题目:13.Roman to IntegerEasy24273630Add to ListShareRoman numerals are represented by seven different symbols:I,V,X,L,C,DandM.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2020-09-01 18:57:25 · 282 阅读 · 0 评论 -
Leet Code OJ 12. Integer to Roman -python
题目:12.Integer to RomanMediumRoman numerals are represented by seven different symbols:I,V,X,L,C,DandM.Symbol ValueI 1V 5X 10L 50C 100D 500M 1...原创 2020-08-31 22:01:40 · 241 阅读 · 0 评论 -
Leet Code OJ 2. Add Two Numbers [Difficulty: Medium] -python
题目:2.Add Two NumbersMediumYou are given twonon-emptylinked lists representing two non-negative integers. The digits are stored inreverse orderand each of their nodes contain a single digit. Add the two numbers and return it as a linked list.Yo...原创 2020-08-30 23:02:49 · 151 阅读 · 0 评论 -
Leet Code OJ 127. Word Ladder [Difficulty: Medium]-python
题目:127.Word LadderMediumGiven two words (beginWordandendWord), and a dictionary's word list, find the length of shortest transformation sequence frombeginWordtoendWord, such that:Only one letter can be changed at a time. Each transformed wor...原创 2020-08-30 16:05:48 · 164 阅读 · 0 评论 -
Leet Code OJ 125. Valid Palindrome [Difficulty: Easy] -python
题目:125.Valid PalindromeEasyGiven a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Note:For the purpose of this problem, we define empty string as valid palindrome.Example 1:Input: "A man,..原创 2020-08-29 21:44:41 · 140 阅读 · 0 评论 -
Leet Code OJ 88. Merge Sorted Array [Difficulty: Easy] -python
题目:88.Merge Sorted ArrayEasyGiven two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:The number of elements initialized innums1andnums2aremandnrespectively. You may assume thatnums1has enough sp...原创 2020-08-29 20:02:41 · 183 阅读 · 0 评论 -
Leet Code OJ 73. Set Matrix Zeroes [Difficulty: Medium] -python
题目73.Set Matrix ZeroesGiven anmxnmatrix. If an element is0, set its entire row and column to0. Do itin-place.Follow up:A straight forward solution using O(mn) space is probably a bad idea. A simple improvement uses O(m+n) space, but stil...原创 2020-08-29 19:12:55 · 111 阅读 · 0 评论 -
Leet Code OJ 70. Climbing Stairs [Difficulty: Easy] -python
爬楼梯问题:70.Climbing StairsEasyYou are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Example 1:Input: 2Output: 2Explanation: There ar...原创 2020-08-28 17:21:18 · 158 阅读 · 0 评论 -
Leet Code OJ 65. Valid Number [Difficulty: Hard]-Python
65.Valid NumberHardValidate if a given string can be interpreted asa decimal number.Some examples:"0"=>true" 0.1 "=>true"abc"=>false"1 a"=>false"2e10"=>true" -90e3 "=>true" 1e"=>false"e3"=>false" 6e-1"=>...原创 2020-08-28 16:50:23 · 160 阅读 · 0 评论 -
Leet Code OJ 57. Insert Interval [Difficulty: Hard] -python
57.Insert Interval[Hard]Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Example 1:Input: intervals = ...原创 2020-08-27 12:18:55 · 156 阅读 · 0 评论 -
Leet Code OJ 56. Merge Intervals [Difficulty: Medium] -Python
56.Merge Intervals【Medium】Given a collection of intervals, merge all overlapping intervals.Example 1:Input: intervals = [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] overlaps, merge them .原创 2020-08-27 12:08:40 · 163 阅读 · 0 评论 -
平安科技2020校招技术岗部分编程题汇总-分糖果
n个小朋友坐在一排,每个小朋友拥有ai个糖果,现在你要在他们之间转移糖果,使得最后所有小朋友拥有的糖果数都相同,每一次,你只能从一个小朋友身上拿走恰好两个糖果到另一个小朋友上,问最少需要移动多少次可以平分糖果,如果方案不存在输出-1。输入描述:每个输入包含一个测试用例。每个测试用例的第一行包含一个整数n(1 <= n <= 100),接下来的一行包含n个整数ai(1 <= ai <= 100)。输出描述:输出一行表示最少需要移动多少次可以平分苹...原创 2020-08-26 22:52:41 · 864 阅读 · 0 评论 -
平安科技2020校招技术岗部分编程题汇总-查找字符串最长公共子串
请编码实现一个命令行工具,找出指定的2个字符串的最长公共子串。输入描述:命令行工具接收两个字符串参数。输入字符串的合法字符集为[a-zA-Z0-9],大小写敏感,无需考虑异常输入场景。输出描述:所找到的公共子串;如果存在多个等长的公共子串,则请按字母序排序,依次打印出所有公共子串,每行一个。输入例子1:1234567 12893457输出例子1:345思路:1.建立一个全0矩阵,如果匹配就+1,取对角线上最大值就是最长公共子串了。...原创 2020-08-26 22:50:54 · 393 阅读 · 0 评论 -
Leet Code OJ 28. Implement strStr() [Difficulty: Easy] -python
28.Implement strStr()EasyImplementstrStr().Return the index of the first occurrence of needle in haystack, or-1if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2Example 2:Input: haystack = "a...原创 2020-08-26 22:36:34 · 134 阅读 · 0 评论 -
Leet Code OJ 21. Merge Two Sorted Lists [Difficulty: Easy] -python
21.Merge Two Sorted Lists[Easy]Merge two sorted linked lists and return it as a newsortedlist. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, 1->3->4Output: 1->1->2-&...原创 2020-08-26 00:12:59 · 129 阅读 · 0 评论 -
Leet Code OJ 20. Valid Parentheses [Difficulty: Easy] -python
20.Valid Parentheses[Easy]Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of brackets. Open brackets m...原创 2020-08-24 22:29:02 · 147 阅读 · 0 评论 -
Leet Code OJ 1. Two Sum [Difficulty: Easy]-Python
题目:1.Two SumGiven an array of integers, returnindicesof the two numbers such that they add up to a specific target.You may assume that each input would haveexactlyone solution, and you may not use thesameelement twice.Example:Given nums =...原创 2020-08-07 22:13:52 · 144 阅读 · 0 评论 -
(当N非常大时)巧用Java函数BigInteger计算N阶乘
先了解一下BigInteger类型。BigInteger n;n=cin.nextBigInteger();//读入一个大整数这里特别要提出出的两种类型:BigInteger 任意大的整数,原则上是,只要你的计算机的内存足够大,可以有无限位的BigInteger 任意大的实数,可以处理小数精度问题。数据类型:数据类型 类型名原创 2018-02-04 17:24:54 · 4251 阅读 · 0 评论 -
2018 蓝桥杯省赛 B 组模拟赛(五)—— 末尾零的个数
题目:思路见下:package jisuanke;import java.util.*;/* 如计算 2009! 的末尾有多少个0:2009/5 = 401 1~2009之间有 401 个数是 5 的倍数(余数省略).401/5 = 80 1~2009 之间有 80 个数是 25 的倍数.80/5 = 16 1~2009 之间有 16 个数是 125 的倍数. 16/5 = 3 ...原创 2018-03-25 23:01:44 · 272 阅读 · 0 评论 -
2018 蓝桥杯省赛 B 组模拟赛(五)—— 快速幂
一个数的整数次幂,是我们在计算中经常用到的,但是怎么可以在 \mathcal{O}(\log (n))O(log(n)) 的时间内算出结果呢?代码框中的代码是一种实现,请分析并填写缺失的代码,求 x^y \mod pxymodp 的结果。答案: pw(x,y / 2, p) * pw(x, y / 2, p) % p...原创 2018-03-26 12:03:06 · 318 阅读 · 0 评论 -
第九届蓝桥杯javaB组小结
个人感觉终究还是遗憾告终。去年参加的是C/C++B组,只拿了省三。今年参加了Java组,今年比去年多了一道代码题。四道结果填空题、一道程序填空、五道编程大题。结果填空题失分了,好可惜,结束了才想起!!!感觉自己和智障一样,如果这题认真检查一下就不会错了,送分题啊-_-第一题算日期,简单题(5分)第二题算方格数,简单题(7分)第三题复数题,简单题(11分)第四题瞎猜的,没思路(17分)第五题代码填空...原创 2018-04-01 16:17:26 · 834 阅读 · 1 评论 -
2015蓝桥真题——加法变乘法
6.加法变乘法我们都知道:1+2+3+ ... + 49 = 1225现在要求你把其中两个不相邻的加号变成乘号,使得结果为2015比如:1+2+3+...+10*11+12+...+27*28+29+...+49 = 2015就是符合要求的答案。请你寻找另外一个可能的答案,并把位置靠前的那个乘号左边的数字提交(对于示例,就是提交10)。注意:需要你提交的是一个整数,不要填写任何多余的内容。思路:设...原创 2018-03-27 20:31:15 · 246 阅读 · 0 评论 -
2013蓝桥杯真题 —— 黄金连分数
//主要考察BigDecimal的用法,以及其函数BigDecimal.divide()的用法。package lanqiaobei;/* * 标题: 黄金连分数黄金分割数0.61803... 是个无理数,这个常数十分重要,在许多工程问题中会出现。有时需要把这个数字求得很精确。对于某些精密工程,常数的精度很重要。也许你听说过哈勃太空望远镜,它首次升空后就发现了一处人工加工错误,对那样...原创 2018-03-22 17:02:30 · 608 阅读 · 0 评论 -
2018 蓝桥杯省赛 B 组模拟赛(五)——B题 素数个数
题目:思路:将8位数全排列,去掉0开头的,然后判断是否为素数。代码如下:package jisuanke;public class Ti2 { public static int[] p=new int[8]; public static int count=0; public static boolean Isexist(int t) { for(int i=0;i<8;i+...原创 2018-03-25 22:55:52 · 321 阅读 · 0 评论 -
2017第八届蓝桥杯Java B组——日期问题
题目:小明正在整理一批历史文献。这些历史文献中出现了很多日期。小明知道这些日期都在1960年1月1日至2059年12月31日。令小明头疼的是,这些日期采用的格式非常不统一,有采用年/月/日的,有采用月/日/年的,还有采用日/月/年的。更加麻烦的是,年份也都省略了前两位,使得文献上的一个日期,存在很多可能的日期与其对应。 比如02/03/04,可能是2002年03月04日、2004年02月03日或...原创 2018-03-30 23:06:02 · 1248 阅读 · 3 评论 -
转-取石子游戏之三种经典博弈总结
转载:http://blog.csdn.net/xuzengqiang/article/details/77738931、取石子游戏之巴什博弈下面这段来自白白の屋的文章的一段:巴什博弈:只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少取一个,最多取m个。最后取光者得胜。 显然,如果n=m+1,那么由于一次最多只能取m个,所以,无论先取者拿转载 2018-02-05 16:42:04 · 930 阅读 · 0 评论 -
(当n属于long范围时)给出一个数n,求1到n中,有多少个数不是2 5 11 13的倍数
本题我未卡数据,因此未AC,但主要写下思路。链接:https://www.nowcoder.net/acm/contest/75/G来源:牛客网时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32768K,其他语言65536K64bit IO Format: %lld题目描述给出一个数n,求1到n中,有多少个数不是2 5 11 13的倍原创 2018-02-04 17:40:25 · 1860 阅读 · 0 评论 -
找规律-打印十字图
历届试题 打印十字图 时间限制:1.0s 内存限制:256.0MB 问题描述小明为某机构设计了一个十字型的徽标(并非红十字会啊),如下所示:..$$$$$$$$$$$$$....$...........$..$$$.$$$$$$$$$.$$$$...$.......$...$$.$$$.$$$$$.$$$.$$.$...$...$...$.$$.$.$$$.$.$$$.$.$$...原创 2018-02-09 22:40:04 · 906 阅读 · 0 评论 -
最小公倍数-核桃的数量
最近三天有些荒废,学习怠慢,没刷题,今天再从一些基础题找感觉吧。加油。 历届试题 核桃的数量 时间限制:1.0s 内存限制:256.0MB 问题描述小张是软件项目经理,他带领3个开发组。工期紧,今天都在加班呢。为鼓舞士气,小张打算给每个组发一袋核桃(据传言能补脑)。他的要求是:1. 各组的核桃数量必须相同2. 各组内必须能平分核桃(当然是不能打碎的)3. 尽量提供满足1,2条件的...原创 2018-02-09 11:59:58 · 224 阅读 · 0 评论 -
矩阵链乘问题小结-动态规划
今天某学弟问我算法问题,我蜜汁尴尬,毕竟算法方面还不是很精通,但是还是仔细研究了一下这道题,发现要用动态规划,简直要崩溃,我压根就没写过动态规划题-_-,就算我回到算法学习的巅峰期,我可能还是不会写……但是既然遇到了不会的,就弄懂来吧。今天学弟问的题:问题 1170: 【能量项链】时间限制: 1Sec 内存限制: 128MB 提交: 50 解决: 14原创 2018-01-27 22:32:19 · 434 阅读 · 0 评论 -
2-对于有重复字符的情况处理-全排列
--不处理重复字符情况的代码--和无重复数字的相比,区别就是要剪掉相同数字的交换,相同数字不予处理。因此在交换前做个判断,判断是否有重复的字符,若重复则不与交换。/* * 处理有重复数字的情况-全排列 */package lanqiao;import java.util.Scanner;public class Main1 { public static原创 2018-01-27 21:45:25 · 415 阅读 · 0 评论 -
1-不处理有重复数字情况-全排列
单纯针对数学问题而言,比如求123的所有不同次序有多少种?123/132/213/231/312/321 一共六种其实n个数就有n!种。前提是不同的n位数。对于全排列问题采用回溯法。针对全排列不处理重复数字问题,代码如下:若是考虑重复数字,则需要进行剪枝处理。package lanqiao;/* * 不处理重复数字的全排列-回溯法模板 * voi原创 2018-01-27 18:01:20 · 664 阅读 · 0 评论 -
回溯法-求全排列
--所谓有路则通,无路则返--理解一比如123,在第一个位置摆放的时候,有3种情况,用一个for循环,第一次找的是1,1就被标记了,再找第二位第三位的时候,1就不可以用了。再找第二位,剩下2和3,由于1被标记了,只可以找2或者3,先取的是2,取后标记2。再找第三位,剩下了3,由于12都被标记了,只可以找3,所以直接就是3。第一个序列123就出来了。由原创 2018-01-27 00:00:18 · 4882 阅读 · 0 评论 -
计蒜客2018 蓝桥杯省赛 B 组模拟赛(一)-H题封印之门
蒜头君被暗黑军团包围在一座岛上,所有通往近卫军团的路都有暗黑军团把手。幸运的是,小岛上有一扇上古之神打造的封印之门,可以通往近卫军团,传闻至今没有人能解除封印。封印之门上有一串文字,只包含小写字母,有 kk种操作规则,每个规则可以把一个字符变换成另外一个字符。经过任意多次操作以后,最后如果能把封印之门上的文字变换成解开封印之门的文字,封印之门将会开启。蒜头君战斗力超强,但是不擅计算,请你帮原创 2018-02-02 19:58:41 · 916 阅读 · 0 评论 -
博弈问题-取石子(D题小牛vs小客)附取石子游戏总结
题目:链接:https://www.nowcoder.net/acm/contest/75/D来源:牛客网时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32768K,其他语言65536K64bit IO Format: %lld题目描述小牛和小客玩石子游戏,他们用n个石子围成一圈,小牛和小客分别从其中取石子,谁先取完谁胜,每次原创 2018-02-05 17:06:54 · 1540 阅读 · 0 评论 -
标准数独游戏-深搜解法
题目:蒜头君今天突然开始还念童年了,想回忆回忆童年。他记得自己小时候,有一个很火的游戏叫做数独。便开始来了一局紧张而又刺激的高阶数独。蒜头君做完发现没有正解,不知道对不对? 不知道聪明的你能否给出一个标准答案?标准数独是由一个给与了提示数字的 9 \times 99×9 网格组成,我们只需将其空格填上数字,使得每一行,每一列以及每一个 3 \times 33×3 宫都没原创 2018-01-30 13:12:13 · 4521 阅读 · 0 评论 -
G题 数列求值-Java_2018 蓝桥杯省赛B组模拟赛(一)
题目:对于一个含有 n+2n+2 个元素的数列,A_0, A_1, \cdots A_nA0,A1,⋯An,满足这样的递归公式\displaystyle A_i = \frac{A_{i-1} + A_{i + 1}}{2} - C_i\ \ \ 1 \le i \le nAi=2Ai−1+Ai+1−Ci 1≤i≤n现在我们知道 A_0,原创 2018-01-30 16:44:19 · 830 阅读 · 0 评论 -
2014蓝桥杯真题 Java B组——扑克序列
7 扑克序列 A A 2 2 3 3 4 4, 一共4对扑克牌。请你把它们排成一行。 要求:两个A中间有1张牌,两个2之间有2张牌,两个3之间有3张牌,两个4之间有4张牌。 请填写出所有符合要求的排列中,字典序最小的那个。例如:22AA3344 比 A2A23344 字典序小。当然,它们都不是满足要求的答案。请通过浏览器提交答案。“A”一定不要用小写字母a,也不...原创 2018-03-25 09:38:49 · 484 阅读 · 0 评论 -
第五届蓝桥杯Java B组——奇怪的分式
package lanqiaobei;/* 奇怪的分式 上小学的时候,小明经常自己发明新算法。一次,老师出的题目是: 1/4 乘以 8/5 小明居然把分子拼接在一起,分母拼接在一起,答案是:18/45 (参见图1.png) 老师刚想批评他,转念一想,这个答案凑巧也对啊,真是见鬼! 对于分子、分母都是 1~9 中的一位数的情况,还有哪些算式可以...原创 2018-03-23 20:26:37 · 226 阅读 · 0 评论