自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

『诞生之时已至,以此修正万象』

『诀别之时已至,以此舍弃世界』

  • 博客(114)
  • 资源 (1)
  • 收藏
  • 关注

原创 【Codewars】Bouncing Balls

Codewars里的 6kyu Kata。题目说明:A child is playing with a ball on the nth floor of a tall building. The height of this floor,h, is known.He drops the ball out of the window. The ball bounces (for ex...

2019-05-31 21:00:19 1018 1

原创 【Codewars】Josephus Permutation

Codewars里的 5kyu Kata。题目说明:This problem takes its name by arguably the most important event in the life of the ancient historian Josephus: according to his tale, he and his 40 soldiers were trappe...

2019-05-31 20:32:48 386

原创 【Codewars】Dubstep

Codewars里的 6kyu Kata。题目说明:Description:Polycarpus works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of ol...

2019-05-31 20:14:06 425

原创 【Codewars】Pick peaks

Codewars里的 5kyu Kata。题目说明:In this kata, you will write a function that returns the positions and the values of the "peaks" (or local maxima) of a numeric array.For example, the arrayarr = [0, ...

2019-05-30 22:17:48 342

原创 【Codewars】Is a number prime?

Codewars里的 6kyu Kata。题目说明:Description:Define a function that takes an integer argument and returns logical valuetrueorfalsedepending on if the integer is a prime.Per Wikipedia, a prime nu...

2019-05-30 22:12:35 803

原创 【Codewars】Find The Parity Outlier

Codewars里的 6kyu Kata。题目说明:You are given an array (which will have a length of at least 3, but could be very large) containing integers. The array is either entirely comprised of odd integers or e...

2019-05-30 22:02:21 266

原创 【Codewars】Simple Pig Latin

Codewars里的 5kyu Kata。题目说明:Move the first letter of each word to the end of it, then add "ay" to the end of the word. Leave punctuation marks untouched.ExamplespigIt('Pig latin is cool'); // ...

2019-05-30 21:55:40 482

原创 【Codewars】Data Reverse

Codewars里的 6kyu Kata。题目说明:Description:A stream of data is received and needs to be reversed.Each segment is 8 bits long, meaning the order of these segments needs to be reversed, for example:...

2019-05-27 18:28:37 299

原创 【Codewars】Multi-tap Keypad Text Entry on an Old Mobile Phone

Codewars里的 6kyu Kata。题目说明:Description:Prior to having fancy iPhones, teenagers would wear out their thumbs sending SMS messages on candybar-shaped feature phones with 3x4 numeric keypads.---...

2019-05-27 16:02:19 521

原创 【Codewars】All Inclusive?

Codewars里的 7kyu Kata。题目说明:Description:Input:a stringstrng an array of stringsarrOutput of functioncontain_all_rots(strng, arr) (or containAllRots or contain-all-rots):a booleantrueif...

2019-05-27 15:23:25 337

原创 【Codewars】Integers: Recreation One

Codewars里的 5kyu Kata。题目说明:Divisors of 42 are : 1, 2, 3, 6, 7, 14, 21, 42. These divisors squared are: 1, 4, 9, 36, 49, 196, 441, 1764. The sum of the squared divisors is 2500 which is 50 * 50, a ...

2019-05-27 15:16:30 304

原创 【Codewars】Maximum subarray sum

Codewars里的 5kyu Kata。题目说明:The maximum sum subarray problem consists in finding the maximum sum of a contiguous subsequence in an array or list of integers:Max.sequence(new int[]{-2, 1, -3, 4, ...

2019-05-20 17:11:13 376

原创 【Codewars】Folding your way to the moon

Codewars里的 7kyu Kata。题目说明:Have you heard about the myth thatif you fold a paper enough times, you can reach the moon with it? Sure you do, but exactly how many? Maybe it's time to write a progra...

2019-05-20 16:57:50 266

原创 【LeetCode】Reverse Bits(颠倒二进制位)

这道题是LeetCode里的第190道题。题目描述:颠倒给定的 32 位无符号整数的二进制位。示例 1:输入: 00000010100101000001111010011100输出: 00111001011110000010100101000000解释: 输入的二进制串 00000010100101000001111010011100 表示无符号整数 43261596...

2019-05-19 19:54:01 133

原创 【LeetCode】House Robber II(打家劫舍 II)

这道题是LeetCode里的第213道题。题目描述:你是一个专业的小偷,计划偷窃沿街的房屋,每间房内都藏有一定的现金。这个地方所有的房屋都围成一圈,这意味着第一个房屋和最后一个房屋是紧挨着的。同时,相邻的房屋装有相互连通的防盗系统,如果两间相邻的房屋在同一晚上被小偷闯入,系统会自动报警。给定一个代表每个房屋存放金额的非负整数数组,计算你在不触动警报装置的情况下,能够偷窃到的最高金额。...

2019-05-19 14:58:10 236

原创 【LeetCode】House Robber(打家劫舍)

这道题是LeetCode里的第198道题。题目描述:你是一个专业的小偷,计划偷窃沿街的房屋。每间房内都藏有一定的现金,影响你偷窃的唯一制约因素就是相邻的房屋装有相互连通的防盗系统,如果两间相邻的房屋在同一晚上被小偷闯入,系统会自动报警。给定一个代表每个房屋存放金额的非负整数数组,计算你在不触动警报装置的情况下,能够偷窃到的最高金额。示例 1:输入: [1,2,3,1]输出...

2019-05-19 14:35:59 157

原创 【LeetCode】Factorial Trailing Zeroes(阶乘后的零)

这道题是LeetCode里的第172道题。题目描述:给定一个整数n,返回n! 结果尾数中零的数量。示例 1:输入: 3输出: 0解释:3! = 6, 尾数中没有零。示例2:输入: 5输出: 1解释:5! = 120, 尾数中有 1 个零.说明:你算法的时间复杂度应为O(logn)。0 来源于 2 * 5,因为在阶乘中,因子 2 肯定...

2019-05-18 19:55:50 136

原创 【LeetCode】Majority Element(求众数)

这道题是LeetCode里的第169道题。题目描述:给定一个大小为n的数组,找到其中的众数。众数是指在数组中出现次数大于⌊ n/2 ⌋的元素。你可以假设数组是非空的,并且给定的数组总是存在众数。示例1:输入: [3,2,3]输出: 3示例2:输入: [2,2,1,1,1,2,2]输出: 2三种方法:摩尔投票法 排序后去中间数 使用哈...

2019-05-18 19:44:05 79

原创 【LeetCode】Excel Sheet Column Title(Excel表列名称)

这道题是LeetCode里的第168道题。题目描述:给定一个正整数,返回它在 Excel 表中相对应的列名称。例如, 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB ...示例 1:输入: 1输出: "A"...

2019-05-18 18:34:23 188

原创 【LeetCode】Two Sum II - Input array is sorted(两数之和 II - 输入有序数组)

这道题是LeetCode里的第167道题。题目描述:给定一个已按照升序排列的有序数组,找到两个数使得它们相加之和等于目标数。函数应该返回这两个下标值index1 和 index2,其中 index1必须小于index2。说明:返回的下标值(index1 和 index2)不是从零开始的。 你可以假设每个输入只对应唯一的答案,而且你不可以重复使用相同的元素。示例:...

2019-05-18 17:14:15 97

原创 【LeetCode】Best Time to Buy and Sell Stock II(买卖股票的最佳时机 II)

这道题是LeetCode里的第122道题。题目描述:给定一个数组,它的第i个元素是一支给定股票第i天的价格。设计一个算法来计算你所能获取的最大利润。你可以尽可能地完成更多的交易(多次买卖一支股票)。注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。示例 1:输入: [7,1,5,3,6,4]输出: 7解释: 在第 2 天(股票价格 = 1)...

2019-05-18 16:40:11 110

原创 【LeetCode】Best Time to Buy and Sell Stock(买卖股票的最佳时机)

这道题是LeetCode里的第121道题。题目描述:给定一个数组,它的第i个元素是一支给定股票第i天的价格。如果你最多只允许完成一笔交易(即买入和卖出一支股票),设计一个算法来计算你所能获取的最大利润。注意你不能在买入股票前卖出股票。示例 1:输入: [7,1,5,3,6,4]输出: 5解释: 在第 2 天(股票价格 = 1)的时候买入,在第 5 天(股票价...

2019-05-18 16:20:50 164

原创 【Codewars】Valid Braces

Codewars里的 6kyu Kata。题目说明:Write a function that takes a string of braces, and determines if the order of the braces is valid. It should returntrueif the string is valid, andfalseif it's inval...

2019-05-18 16:12:30 408

原创 【Codewars】The Supermarket Queue

Codewars里的 6kyu Kata。题目说明:There is a queue for the self-checkout tills at the supermarket. Your task is write a function to calculate the total time required for all the customers to check out!...

2019-05-18 15:52:50 730

原创 【Codewars】Shortest Word

Codewars里的 7kyu Kata。题目说明:Simple, given a string of words, return the length of the shortest word(s).String will never be empty and you do not need to account for different data types.使用双指针解...

2019-05-18 15:22:33 389

原创 【LeetCode】Pascal's Triangle II(杨辉三角 II)

这道题是LeetCode里的第119道题。题目描述:给定一个非负索引k,其中k≤33,返回杨辉三角的第k行。在杨辉三角中,每个数是它左上方和右上方的数的和。示例:输入: 3输出: [1,3,3,1]进阶:你可以优化你的算法到O(k) 空间复杂度吗?直接把 118 的拿过来改改就行了呗!偷懒可以,但是该学的算法还是得学啊!其实这题可以算...

2019-05-03 23:23:46 130

原创 【Codewars】Build a pile of Cubes

Codewars里的 6kyu Kata。题目说明:Your task is to construct a building which will be a pile of n cubes. The cube at the bottom will have a volume of n^3, the cube above will have volume of (n-1)^3 and so...

2019-05-03 22:17:56 537

原创 【Codewars】Abbreviate a Two Word Name

Codewars里的 8kyu Kata。题目说明:Write a function to convert a name into initials. This kata strictly takes two words with one space in between them.The output should be two capital letters with a dot...

2019-05-03 21:53:06 408

原创 【Codewars】Multiply

Codewars里的注册题。没有完成这道题就不能注册账号。题目说明:The code does not execute properly. Try to figure out why.解题方法:public class Multiply { public static Double multiply(Double a, Double b) { ret...

2019-05-03 21:45:02 454

原创 【LeetCode】Minimum Depth of Binary Tree(二叉树的最小深度)

这道题是LeetCode里的第111道题。题目描述:给定一个二叉树,找出其最小深度。最小深度是从根节点到最近叶子节点的最短路径上的节点数量。说明:叶子节点是指没有子节点的节点。示例:给定二叉树[3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7返回它的最小深度 2.递归解决。调...

2019-05-01 21:41:50 92

原创 【LeetCode】Convert Sorted Array to Binary Search Tree(将有序数组转换为二叉搜索树)

这道题是LeetCode里的第108道题。题目描述:将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索树。本题中,一个高度平衡二叉树是指一个二叉树每个节点的左右两个子树的高度差的绝对值不超过 1。示例:给定有序数组: [-10,-3,0,5,9],一个可能的答案是:[0,-3,9,-10,null,5],它可以表示下面这个高度平衡二叉搜索树: 0...

2019-05-01 21:09:15 94

原创 【LeetCode】Binary Tree Level Order Traversal II(二叉树的层次遍历 II)

这道题是LeetCode里的第107道题。题目描述:给定一个二叉树,返回其节点值自底向上的层次遍历。 (即按从叶子节点所在层到根节点所在的层,逐层从左向右遍历)例如:给定二叉树[3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7返回其自底向上的层次遍历为:[ [15,7], [9,...

2019-04-30 22:47:54 115

原创 【LeetCode】Pascal's Triangle(杨辉三角)

这道题是LeetCode里的第118道题。题目描述:给定一个非负整数numRows,生成杨辉三角的前numRows行。在杨辉三角中,每个数是它左上方和右上方的数的和。示例:输入: 5输出:[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]题目虽然看起来简单,而且大部分人都做过,但是...

2019-04-30 22:39:48 118

原创 【LeetCode】Valid Palindrome(验证回文串)

这道题是LeetCode里的第125道题。题目描述:给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。说明:本题中,我们将空字符串定义为有效的回文串。示例 1:输入: "A man, a plan, a canal: Panama"输出: true示例 2:输入: "race a car"输出: false三个步骤:小...

2019-04-30 22:27:42 103

原创 【LeetCode】Min Stack(最小栈)

这道题是LeetCode里的第155道题。题目描述:设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的栈。push(x)-- 将元素 x 推入栈中。 pop()-- 删除栈顶的元素。 top()-- 获取栈顶元素。 getMin() -- 检索栈中的最小元素。示例:MinStack minStack = new MinStack();...

2019-04-30 21:51:35 334

原创 【LeetCode】Count Primes(计数质数)

这道题是LeetCode里的第204道题。题目描述:统计所有小于非负整数n的质数的数量。示例:输入: 10输出: 4解释: 小于 10 的质数一共有 4 个, 它们是 2, 3, 5, 7 。这道题很有意思,使用的是 厄拉多塞筛法,基本思想是用一个记录数组记录是否为质,质数为 0,反之为合数。可以确定两点:x 是素数,x 的倍数肯定不是素数 若 x 不是素数...

2019-04-30 20:58:04 248

原创 【LeetCode】Sqrt(x)(x 的平方根)

这道题是LeetCode里的第69道题。题目描述:实现int sqrt(int x)函数。计算并返回x的平方根,其中x是非负整数。由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去。示例 1:输入: 4输出: 2示例 2:输入: 8输出: 2说明: 8 的平方根是 2.82842..., 由于返回类型是整数,小数部分将被...

2019-04-30 20:39:16 131

原创 【LeetCode】Single Number(只出现一次的数字)

这道题是LeetCode里的第136道题。题目描述:给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。说明:你的算法应该具有线性时间复杂度。 你可以不使用额外空间来实现吗?示例 1:输入: [2,2,1]输出: 1示例2:输入: [4,1,2,1,2]输出: 4方法一:使用哈希表,建立一个哈希数...

2019-04-30 20:29:29 310

原创 【LeetCode】Power of Four(4的幂)

这道题是LeetCode里的第342道题。题目描述:给定一个整数 (32 位有符号整数),请编写一个函数来判断它是否是 4的幂次方。示例 1:输入: 16输出: true示例 2:输入: 5输出: false进阶:你能不使用循环或者递归来完成本题吗?解题代码:class Solution { public boolean isPowe...

2019-04-27 17:29:45 233

原创 【LeetCode】Power of Three(3的幂)

这道题是LeetCode里的第326道题。题目描述:给定一个整数,写一个函数来判断它是否是 3的幂次方。示例 1:输入: 27输出: true示例 2:输入: 0输出: false示例 3:输入: 9输出: true示例 4:输入: 45输出: false进阶:你能不使用循环或者递归来完成本题吗?数论的知识,3 的幂次的质因...

2019-04-27 17:23:12 161

C++ 程序设计语言(1~4)

本书把入门起点降低,读者不需要具备C语言的基础。本书包括14章,分为4篇:基本知识;面向过程的程序设计;基于对象的程序设计;面向对象的程序设计。本书内容全面,例题丰富,概念清晰,循序渐进,易于学习。

2018-06-10

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除