leetcode
木杉Vincent
这个作者很懒,什么都没留下…
展开
-
LeetCode217. Contains Duplicate解题
大家好,我又回来了,隔了一个星期没有刷题了 在这一个星期我想了很多,Java虽然上手容易,用着也很顺手,我目前最熟悉的也还是Java,但是Java语言的设计局限了它不能做很底层的东西,它实用性很强,但是LeetCode是偏向算法的,基础的东西,我觉得还是C++比较方便,也比较考验能力,因此我决定使用C++来解题先来看一下题目 Given an array of integers, find i原创 2017-10-31 14:37:38 · 207 阅读 · 0 评论 -
LeetCode485:Max Consecutive Ones 解答
题目先来看一下题目: Given a binary array, find the maximum number of consecutive 1s in this array.Example 1: Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are con原创 2017-10-16 08:03:24 · 221 阅读 · 0 评论 -
LeetCode695:Max Area of Island 解答
写这道题用了我一个小时的时间,算是比较难的一道题目,解题的过程也很干净利落下面来看一下题目 Given a non-empty 2D array grid of 0’s and 1’s, an island is a group of 1’s (representing land) connected 4-directionally (horizontal or vertical.) You m原创 2017-10-16 15:59:38 · 2047 阅读 · 0 评论 -
LeetCode448. Find All Numbers Disappeared in an Array 解答
现在才发现每次提交的时候runtime是不同的,可能这一次提交的runtime是20ms,但是下一次提交的runtime就是18ms了,所以以后还是老老实实用时间复杂度来衡量吧23333先来看一下题目 Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and原创 2017-10-16 20:21:47 · 156 阅读 · 0 评论 -
LeetCode283. Move Zeroes 解答
这也是乍一看好简单结果写的我想撞墙的那种题来看一下题目 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 example, given nums = [0, 1,原创 2017-10-16 21:24:28 · 211 阅读 · 0 评论 -
LeetCode697. Degree of an Array解答
一早上起来,先做一道题降降起床气,这道题花了一个小时多十分钟,但是!当我看到accept之后的结果了的时候! 贼开心老规矩,先看一下题目 Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one原创 2017-10-17 10:27:48 · 2383 阅读 · 0 评论 -
LeetCode 122. Best Time to Buy and Sell Stock II解答
废话不多说先来看一下题目 Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you原创 2017-10-17 14:00:26 · 213 阅读 · 0 评论 -
LeetCode169. Majority Element解答
天气冷了 ,有男朋友的抱男朋友,有女朋友的抱女朋友,而我就比较牛逼了 我不冷原创 2017-10-19 16:51:25 · 186 阅读 · 0 评论 -
LeetCode121. Best Time to Buy and Sell Stock解题
乍一看这题很熟悉,原来之前做过它的第二道,参见 LeetCode122.Best Time to Buy and Sell Stock解题 @GhostLWB来看一下题目Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted t原创 2017-11-23 11:50:34 · 213 阅读 · 0 评论 -
LeetCode 2:Add Two Numbers解题
终于,隔了很久之后,我又开始题了。 其实刷OJ是为了保研机试提前做准备,也是为了给自己的编程知识保温,但是当我发现自己两个月了还在刷easy难度的题目的时候,我知道,我得挑战点真正的题目了。还是先来看一下今天的题目You are given two non-empty linked lists representing two non-negative integers. The d原创 2018-01-24 14:54:40 · 238 阅读 · 0 评论 -
LeetCode238. Product of Array Except Self解题
看一下题目Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O(n).原创 2017-11-27 08:37:31 · 194 阅读 · 0 评论 -
Leetcode 463. Island Perimeter 解题
好久没有刷题,甚是怀念这种刷题的感觉 最近有刷杭电oJ POJ也试着刷了一下,还有个国外的平台我忘了叫啥了 感觉LeetCode的平台很人性化,能够在提交之前自己尝试运行,并且能够告诉你WA之前最后一次测试数据是什么,方便寻找错误原因,并且AC之后还能看到别人的AC代码(这是我最欣赏的一点!)这样就能学习到更好的算法,不过它的playground我还不是很会用,调试还得在本地进行。但是测试用例有原创 2017-12-11 15:56:35 · 249 阅读 · 0 评论 -
LeetCode442. Find All Duplicates in an Array解题
忙一点总比闲着好,是吧先来看一下题目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 that appear twice in this array.Could you do it w原创 2017-11-21 15:17:08 · 179 阅读 · 0 评论 -
LeetCode717. 1-bit and 2-bit Characters 解题
废话不多说,先来看题目看一下题目We have two special characters. The first character can be represented by one bit 0.原创 2017-11-15 17:27:21 · 1478 阅读 · 2 评论 -
LeetCode268. Missing Number解题
Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.For example, Given nums = [0, 1, 3] return 2.Note: Your algorithm should run in line原创 2017-11-18 21:05:06 · 168 阅读 · 0 评论 -
LeetCode628. Maximum Product of Three Numbers 解题
先看看题目:先看看题目:Given an integer array, find three numbers whose product is maximum and output the maximum product. 题目意思是说,给定一个整数的数组,找到三个能产生最大的积的数看一下例子 Example 1: Input: [1,2,3] Output: 6 E原创 2017-11-17 21:08:45 · 214 阅读 · 0 评论 -
LeetCode566:reshape matrix 解答
写在前面:我已经很久没有建设我的CSDN博客了,最近开始刷LeetCode,打算把我的解题过程记录成博客,既是一种总结,也是一种分享。在此先立个flag,在十一月三十日之前把array类的easy等级的题目都刷完(一共34道),并且都记录在博客中,希望不要让我自己打脸。 ———————————–分割线——————————————-题目In MATLAB, there is a very usefu原创 2017-10-15 19:48:17 · 311 阅读 · 0 评论