
leetcode
文章平均质量分 77
Lukia2015
这个作者很懒,什么都没留下…
展开
-
ZigZag Conversion (C实现)
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H NA P L S I原创 2015-09-08 14:40:11 · 1140 阅读 · 0 评论 -
Ugly Number I II 解析
leetcode上关于ugly number(丑数)的题目有两个,先说一下什么叫丑数,很多博客上关于丑数的解释有比较模糊,有的解释成能被2,3,5整除的数,这是很难理解的一句话,比如14,35明明可以被2和5整除却不是丑数。其实丑数是一种能写成2,3,5的乘方组合(number == 2^m*3^n*5^k,m,n,k为自然数)的形式的数字,比如 180这个数字,可以写成2*2*3*3*5,它原创 2015-09-15 18:20:28 · 477 阅读 · 0 评论 -
Leetcode-201- Bitwise AND of Numbers Range
Given a range [m, n] where 0 For example, given the range [5, 7], you should return 4. 题意:m到n若干个数字按位与运算的最后结果,比如5-7,写成2进制分别是0101,0110,0111与运算后得到0100,结果为4。解析:理解了提议之后,就可以立马想到一个暴力破解的方法,直接从m与运算到n就得了呗原创 2015-10-22 09:47:44 · 510 阅读 · 0 评论 -
Trapping Rain Water C#
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]原创 2015-09-23 16:36:14 · 498 阅读 · 0 评论 -
Leetcode-149-Max Ponits on a Line C#
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.题意:找到在同一直线上的点的最大个数。分析:首先看这个题的暴力方法,两点确定一条直线,所以确定下一条直线后,挨个验证剩下的点是不是也在这条直线上,并记录个数,O(n^3)的时间复杂度就可以解决问原创 2015-11-12 15:30:48 · 437 阅读 · 0 评论 -
Median of Two Sorted Arrays C++
这道题目很多人认为是leetcode上最经典的题目之一,很早之前就见过这个题目,好像算法导论也有讲过这个题。题意是找两个排好序的数组的中位数,如果不去考虑时间空间复杂度,这个问题极其简单,用merge排序将一个数组归并到另一个数组中去,然后就可以立马找到中位数,不过这样的时间空间复杂度都比较高,其实,按照这个思路写出来的代码也可以AC,可见leetcode的AC标准也不是很严格。那么这个题有没原创 2015-09-24 16:25:47 · 550 阅读 · 0 评论 -
Leetcode-134-Gas Station C#
There are N gas stations along a circular route, where the amount of gas at stationi is gas[i]. You have a car with an unlimited gas tank and it costscost[i] of gas to travel from station i to i原创 2015-10-29 09:24:31 · 553 阅读 · 0 评论 -
Leetcode-239-Sliding Window Maximum
Given an array nums, there is a sliding window of sizek which is moving from the very left of the array to the very right. You can only see thek numbers in the window. Each time the sliding window原创 2015-11-18 10:03:52 · 389 阅读 · 0 评论 -
Leetcode-43-Multiply Strings C#
Given two numbers represented as strings, return multiplication of the numbers as a string.题意:给两个字符串,返回这两个字符串代表的数字的乘积字符串。解析:把字符串转换成数字,做乘法,再将结果转化回字符串,这种方法肯定是不行的,因为上限问题。所以需要自己实现一个乘法算法。乘法都学过,1234原创 2015-11-02 10:36:41 · 657 阅读 · 0 评论 -
Leetcode-8-String to Integer(atoi) C++
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca原创 2016-06-27 14:24:44 · 1365 阅读 · 0 评论 -
Leetcode-91-Decode Ways C#
A message containing letters fromA-Z is being encoded to numbers using the following mapping: 'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu原创 2015-11-03 16:16:25 · 747 阅读 · 0 评论 -
Valid Parentheses C#
Given a string containing just the characters '(', ')', '{', '}', '[' and']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all val原创 2015-09-08 15:35:00 · 449 阅读 · 0 评论 -
Divide Two Integers C#
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.题意:实现一个除法,不能用division,mod,multiplication这三种运算。当然了能用division,写个毛线啊。这些都不能用,运算里面只有加法了原创 2015-09-07 13:55:53 · 572 阅读 · 0 评论 -
Generate Parentheses C++
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()原创 2015-09-11 14:37:12 · 419 阅读 · 0 评论 -
Number of Islands C++
Given a 2d grid map of '1's (land) and'0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assum原创 2015-09-11 10:09:33 · 1251 阅读 · 0 评论 -
Remove Duplicates from Sorted Array II C#
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原创 2015-08-31 15:04:40 · 337 阅读 · 0 评论 -
Combination Sum III C#
Find all possible combinations of k numbers that add up to a numbern, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Ensure that numbers wit原创 2015-08-24 09:16:17 · 434 阅读 · 0 评论 -
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原创 2015-08-26 15:21:09 · 328 阅读 · 0 评论 -
Best Time to Buy and Sell Stock C#
Say you have an array for which the ith element is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),原创 2015-08-24 10:51:25 · 562 阅读 · 0 评论 -
Search for a Range C#
Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not found in原创 2015-08-27 09:45:20 · 267 阅读 · 0 评论 -
Subsets C#
Given a set of distinct integers, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For ex原创 2015-08-26 14:16:14 · 625 阅读 · 0 评论 -
Leetcode-89 Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of原创 2016-10-25 10:55:25 · 439 阅读 · 0 评论