随笔分类 -  Leetcode+题

摘要:Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. Some hints: Could negative integers be palindromes? 阅读全文
posted @ 2017-07-03 17:10 王大咩的图书馆 阅读(217) 评论(0) 推荐(0)
摘要:Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't ma 阅读全文
posted @ 2017-07-03 16:39 王大咩的图书馆 阅读(154) 评论(0) 推荐(0)
摘要:Given n non-negative integers a1 , a2 , ..., an , where each represents a point at coordinate (i, ai ). n vertical lines are drawn such that the two e 阅读全文
posted @ 2017-07-03 16:14 王大咩的图书馆 阅读(270) 评论(0) 推荐(0)
摘要:Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of 阅读全文
posted @ 2017-07-03 00:44 王大咩的图书馆 阅读(213) 评论(0) 推荐(1)
摘要:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. 阅读全文
posted @ 2017-07-02 23:52 王大咩的图书馆 阅读(331) 评论(0) 推荐(0)
摘要:Given an unsorted integer array, find the first missing positive integer. For example,Given[1,2,0]return3,and[3,4,-1,1]return2. Your algorithm should 阅读全文
posted @ 2017-07-02 22:36 王大咩的图书馆 阅读(211) 评论(0) 推荐(0)
摘要:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possib 阅读全文
posted @ 2017-07-02 15:55 王大咩的图书馆 阅读(206) 评论(0) 推荐(0)
摘要:Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume that A has enough space to hold additional elements 阅读全文
posted @ 2017-07-02 10:27 王大咩的图书馆 阅读(139) 评论(0) 推荐(0)
摘要:Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For example,Given sorted array A =[1,1,1,2,2,3], Your function should 阅读全文
posted @ 2017-07-02 01:26 王大咩的图书馆 阅读(336) 评论(0) 推荐(0)
摘要:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space fo 阅读全文
posted @ 2017-07-01 17:17 王大咩的图书馆 阅读(243) 评论(0) 推荐(0)
摘要:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, 阅读全文
posted @ 2017-07-01 16:36 王大咩的图书馆 阅读(426) 评论(0) 推荐(0)
摘要:Given a collection of intervals, merge all overlapping intervals. For example,Given[1,3],[2,6],[8,10],[15,18],return[1,6],[8,10],[15,18]. 题意:给定一系列区间,合 阅读全文
posted @ 2017-07-01 11:19 王大咩的图书馆 阅读(294) 评论(0) 推荐(0)
摘要:Given an integer n, generate a square matrix filled with elements from 1 to n 2 in spiral order. For example,Given n =3, You should return the followi 阅读全文
posted @ 2017-07-01 10:29 王大咩的图书馆 阅读(241) 评论(0) 推荐(1)
摘要:Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example,Given the following matrix: You s 阅读全文
posted @ 2017-06-30 22:20 王大咩的图书馆 阅读(257) 评论(0) 推荐(0)
摘要:You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up:Could you do this in-place? 方法一:常规思路: 将图 阅读全文
posted @ 2017-06-30 21:39 王大咩的图书馆 阅读(358) 评论(0) 推荐(0)
摘要:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted f 阅读全文
posted @ 2017-06-30 13:14 王大咩的图书馆 阅读(235) 评论(0) 推荐(0)
摘要:Given a number represented as an array of digits, plus one to the number. 题意:给定数以数组的形式存储,然后计算该数加1的值。 思路:一般遇到这种以数组,或字符串形式的数相加的问题,都是从右往左遍历(因为,数的低位在右边),用 阅读全文
posted @ 2017-06-30 09:45 王大咩的图书馆 阅读(196) 评论(0) 推荐(1)
摘要:Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 题意:将已排序的数组转成高度平衡的搜索二叉树。 思路:这题和Convert sorted list to 阅读全文
posted @ 2017-06-29 20:49 王大咩的图书馆 阅读(171) 评论(0) 推荐(0)
摘要: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. You may compl 阅读全文
posted @ 2017-06-29 20:36 王大咩的图书馆 阅读(338) 评论(0) 推荐(0)
摘要: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. You may compl 阅读全文
posted @ 2017-06-29 16:54 王大咩的图书馆 阅读(266) 评论(0) 推荐(0)