
LeetCode
文章平均质量分 66
sunp823
积跬步,至千里;积小流,成江海
展开
-
LeetCode题目_Reverse Integer
最近在LeetCode上做题,写点东西记录一下,虽然自己做的都是些很水的题目,但是重在练手。题号7:Reverse Integer,题目描述:Reverse digits of an integer:例如,输入123,输出321;输入-123,输出-321。思路很简单:将原数的每一位求出,然后将原数的每一位倒序,生成一个整数。在程序中,使用了队列,利用其先进先出的原则,倒序原数每一位。原创 2015-04-12 00:15:58 · 430 阅读 · 0 评论 -
LeetCode—Minimum Size Subarray Sum
题目:Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the a原创 2015-05-18 01:05:21 · 407 阅读 · 0 评论 -
LeetCode--Sum Root to Leaf Numbers
题目:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number123.Find the to原创 2015-05-19 00:35:12 · 412 阅读 · 0 评论 -
leetcode_Basic Calculator
题目:Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers原创 2015-06-30 23:43:19 · 362 阅读 · 0 评论 -
leetcode_Basic Calculator II
题目:Implement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer divisi原创 2015-06-30 23:47:39 · 466 阅读 · 0 评论 -
二叉树最近公共祖先节点
寻找最近公共祖先节点(LCA)在一棵二叉树中,对于节点X和节点Y,X和Y的LCA是这棵树中X和Y的第一个共同祖先。寻找公共节点的算法思路很简单:对于节点x和y,找到树的根节点分别到x节点和y节点的路径(并不是遍历),并分别记录在两个数组中(或其他),数组中索引为0的元素为树的根节点,索引越小的元素离待x和y节点越远。且两个数组前面肯定有对应相同的元素。此时问题变为正向查找两个数组中第一个不相同原创 2015-07-13 15:39:22 · 1465 阅读 · 0 评论 -
leetcode之Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0原创 2015-11-15 23:18:01 · 607 阅读 · 0 评论 -
字符串交错组成--很优美的递归算法
问题:对于三个字符串A,B,C。我们称C由A和B交错组成当且仅当C包含且仅包含A,B中所有字符,且对应的顺序不改变。请编写一个高效算法,判断C串是否由A和B交错组成。给定三个字符串A,B和C,及他们的长度。请返回一个bool值,代表C是否由A和B交错组成。代码如下:class Mixture {public: bool chkMixture(string原创 2016-03-10 17:06:08 · 703 阅读 · 0 评论 -
Rotate Image(二位数组顺时针旋转)
问题描述: 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? 中文题目: 有一个NxN整数矩阵,请编写一个算法,将矩阵顺时针旋转90度。 给定一个NxN的矩阵,原创 2016-03-24 16:53:40 · 879 阅读 · 1 评论 -
leetcode_Count Numbers with Unique Digits
leetcode_Count Numbers with Unique DigitsGiven a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n.原创 2016-07-05 16:32:05 · 303 阅读 · 0 评论 -
LeetCode_Compare Version Numbers
题目:Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty a原创 2015-05-27 23:22:26 · 322 阅读 · 0 评论 -
LeetCode—Longest Consecutive Sequence
题目描述: Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example, Given [100, 4, 200, 1, 3, 2], The longest consecutive elements sequence is [1, 2,原创 2015-05-20 18:07:49 · 380 阅读 · 0 评论 -
LeetCode—Unique Paths
题目:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach原创 2015-05-07 00:26:20 · 349 阅读 · 0 评论 -
LeetCode_Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.原创 2015-04-20 00:37:28 · 339 阅读 · 0 评论 -
LeetCode_Search in Rotated Sorted Array
题目:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array return原创 2015-04-20 00:50:15 · 323 阅读 · 0 评论 -
LeetCode_Insertion Sort List
题目:Sort a linked list using insertion sort,即仿照插入排序(直接插入排序)对一个链表排序。插入排序的思想:总共进行n-1趟排序,在排列第i个元素时,前面的i个元素是有序的,将第i个元素插入到前i个元素中,并且保证被插入的数组是有序的,数组是顺序存储的,因此向有序的数组插入一个元素时,需要从插入位置之后的各个元素后移。这就是插入排序的思想。插入排序的时间原创 2015-04-14 23:54:40 · 617 阅读 · 0 评论 -
LeetCode_Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Yo原创 2015-04-14 23:39:47 · 625 阅读 · 0 评论 -
LeetCode_Pascal's Triangle
https://leetcode.com/problems/pascals-triangle/Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1],原创 2015-04-16 02:26:01 · 329 阅读 · 0 评论 -
LeetCode_Merge Two Sorted Lists
问题:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.将两个有序链表合为一个有序的链表并返回头指针。/** * Definition for singly-原创 2015-04-17 01:46:04 · 641 阅读 · 0 评论 -
LeetCode_Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where原创 2015-04-17 01:50:25 · 683 阅读 · 0 评论 -
LeetCode_Isomorphic Strings
Isomorphic StringsGiven two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be原创 2015-04-30 01:07:05 · 376 阅读 · 0 评论 -
LeetCode_Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine i原创 2015-04-28 01:09:05 · 324 阅读 · 0 评论 -
leetcode_Valid Perfect Square
Valid Perfect SquareGiven a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built-in library function such as sqrt.原创 2016-07-05 16:58:25 · 366 阅读 · 0 评论