我的代码游记

分类 · LeetCode

首页

关于

归档

计数LeetCodeMedium数组

80.Remove Duplicates from Sorted Array II(Medium)

Follow up for “Remove Duplicates”:What if duplicates are allowed at most twice?给定一个有序的整数数列,每个数最多只能出现两次,然后去除多余的数,把剩下的数排在原数组的前面,并返回新数列的长度 *  这虽然是个中等题,不过难度不大,唯一需要多考虑的就是在原数组前面排列新的数组* For example Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the first five elements of nums being 1, 1, 2, 2 and 3. It doesn’t matter what ..

更多
loading..
搜索LeetCodeEasy一行实现

500.Keyboard Row(Easy)

Given a List of words, return the words that can be typed using letters of alphabet on only one row’s of American keyboard like the image below. *  虽然还把键盘搬出来了,但是实际上只是搜索每一个String的字母是否在键盘的同一行出现,键盘的每一行只要用一个String代替就ok了,剩下的问题显然就简单了。* For example Input: [“Hello”, “Alaska”, “Dad”, “Peace”]Output: [“Alaska”, “Dad”] My Solution(Java) Version 1 Time: 3ms:  简单..

更多
LeetCodeEasy二分查找

374.Guess Number Higher or Lower(Easy)

We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I’ll tell you whether the number is higher or lower.You call a pre-defined API guess(int num) which returns 3 possible results (-1, 1, or 0):我们来玩一个猜数游戏,游戏规则是这样的:我从1~n中选择一个数,你需要猜我选的数是哪一个,如果你猜错的话,我就会告诉你你猜的数比我..

更多
LeetCodeEasy一行实现动态规划

121. Best Time to Buy and Sell Stock(Easy)

Say you have an array for which the i element is the price of a given stock on day i.给定一个数组,其中第i个元素是第i天是这个股票的价格 If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.如果你仅被允许交易一次(即买一支股票和卖一支股票),设计一个算法来找到最大的利润 *  这个题目有点绕,其实就是在一个数组中找到差值(利润)最大的两个数,但是关键在于题目..

更多
1238