Leetcode
文章平均质量分 61
每天都要有进步
这个作者很懒,什么都没留下…
展开
-
Leetcode #131 Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","原创 2015-08-25 05:03:04 · 270 阅读 · 0 评论 -
Leetcode #130 Surrounded Regions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,X X X XX O O X原创 2015-08-25 08:22:26 · 234 阅读 · 0 评论 -
Leetcode #237 Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with val原创 2015-08-27 11:13:57 · 238 阅读 · 0 评论 -
Leetcode #136 Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using e原创 2015-08-09 00:48:03 · 217 阅读 · 0 评论 -
Leetcode #235 Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betw原创 2015-08-28 04:28:10 · 205 阅读 · 0 评论 -
Leetcode #226 Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Difficulty: Easy# Definition for a binary tree node.# class Tree原创 2015-08-28 23:47:52 · 309 阅读 · 0 评论 -
Leetcode #141 Linked List Cycle Python
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Difficulty:Medium不占用额外地址的做法,两个node一个每次跳一次,一个每次跳两下next,如果碰到none就返回False,如果这个两个nod原创 2015-08-29 01:44:53 · 427 阅读 · 0 评论 -
Leetcode #191 Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation 000000原创 2015-08-28 04:25:48 · 241 阅读 · 0 评论 -
Leetcode 258 258
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has on原创 2015-08-27 11:11:50 · 298 阅读 · 0 评论 -
Leetcode#12 Integer to Roman
Difficulty: Medium这个暑假做的第一个中等题,思路和#13一样的,一点都不难,但是在string处理上花了点时间,收获不少。#include #include #include using namespace std;string toString(int a, int b){ string s; char c1,c2,c3;原创 2015-06-22 15:15:41 · 269 阅读 · 0 评论 -
Leetcode#3 Longest Substring Without Repeating Characters
Difficulty:MediumGiven a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which原创 2015-07-02 02:38:44 · 232 阅读 · 0 评论 -
Leetcode8# String to Integer (atoi)
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原创 2015-07-04 23:00:44 · 200 阅读 · 0 评论 -
Leetcode#26 Remove Duplicates from Sorted Array
Difficulty: EasyGiven 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 for another array, you must原创 2015-07-06 22:50:00 · 202 阅读 · 0 评论 -
Leetcode# 38 Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as原创 2015-07-12 22:53:11 · 243 阅读 · 0 评论 -
Leetcode #59 Spiral Matrix II
Difficulty: MediumGiven an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1,原创 2015-07-25 23:26:51 · 253 阅读 · 0 评论 -
Leetcode #77 Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]原创 2015-07-31 22:29:07 · 235 阅读 · 0 评论 -
Leetcode #78 Subsets
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原创 2015-07-31 22:54:13 · 301 阅读 · 0 评论 -
Leetcode#15 3Sum
Difficulty:MediumGiven 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 zero.Note:Element原创 2015-07-05 22:12:19 · 214 阅读 · 0 评论 -
Leetcode #62 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 the原创 2015-07-21 16:46:58 · 237 阅读 · 0 评论 -
Leetcode # 81Search in Rotated Sorted Array II
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the原创 2015-08-01 23:19:07 · 211 阅读 · 0 评论 -
Leetcode#9 Palindrome Number(两种方法)
Difficulty:Easyclass Solution {public: bool isPalindrome(int x) { int left,right; if(x<0) return false; if(x==0) return true; int k = 1, flag =原创 2015-06-23 00:25:33 · 290 阅读 · 0 评论 -
Leetcode#1 Two Sum
Difficulty: MediumGiven 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原创 2015-06-26 00:03:44 · 252 阅读 · 0 评论 -
Leetcode #28 Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Update (2014-11-02):The signature of the function had been updat原创 2015-07-08 22:03:10 · 231 阅读 · 0 评论 -
Leetcode #27 Remove Element
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 matter what you leave beyond the new length.D原创 2015-07-08 21:28:01 · 221 阅读 · 0 评论 -
Leetcode #49 Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.Difficulty: Medium典型的hash,用map做。在此我得到了一个小启发,使用sort()重新排列字母比较会比较简单。v原创 2015-07-20 01:18:47 · 292 阅读 · 0 评论 -
Leetcode #40 Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combina原创 2015-07-14 00:01:54 · 231 阅读 · 0 评论 -
Leetcode#35 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-07-11 19:06:15 · 260 阅读 · 0 评论 -
Leecode#31 Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible原创 2015-07-10 22:46:27 · 316 阅读 · 0 评论 -
Leetcode # 240 Search a 2D Matrix II
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 in ascending from left to right.Integers in原创 2015-07-29 17:16:12 · 235 阅读 · 0 评论 -
Leetcode #80 Remove Duplicates from Sorted Array II
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 fi原创 2015-08-01 14:01:05 · 210 阅读 · 0 评论 -
Leetcode#7 Reverse Integer !!!Update (2014-11-10)之后的版本!!!
去年11月份的更新导致CSDN博客里老的题解都是错的。其实很简单,用long long 考虑下是否溢出,本人愚笨,用最土的方法,不过至少在两CE,两次WA之后AC了,开森~!题目:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321原创 2015-06-24 00:49:43 · 197 阅读 · 0 评论 -
Leetcode#5 Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.Difficulty: Medium原创 2015-07-04 21:21:43 · 242 阅读 · 0 评论 -
Leetcode#20 Valid Parentheses
Difficulty: EasyGiven a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and原创 2015-07-05 22:46:20 · 170 阅读 · 0 评论 -
Leetcode # 153 Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the largest原创 2015-07-20 23:04:54 · 244 阅读 · 0 评论 -
Leetcode #60 Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""213""231""3原创 2015-07-26 22:49:30 · 215 阅读 · 0 评论 -
Leetcode #64 Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at原创 2015-07-28 02:28:23 · 238 阅读 · 0 评论 -
Leetcode #79 Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically原创 2015-08-01 13:27:27 · 258 阅读 · 0 评论 -
Leetcode#14 Longest Common Prefix
很简答的一题,因为我if(strs.size()==0) return "";和 string prefix; prefix = strs[0];的顺序写翻了runtimerror了一个小时,醉了。。。string longestCommonPrefix(vector& strs) { if(strs.size()=原创 2015-06-25 01:42:27 · 302 阅读 · 0 评论 -
Leetcode #17 Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit st原创 2015-07-08 21:14:48 · 330 阅读 · 0 评论 -
Leetcode #171 Excel Sheet Column Number
Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ...原创 2015-08-30 10:41:17 · 219 阅读 · 0 评论