- 博客(42)
- 收藏
- 关注
原创 Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Have you met this question in a real interview? YesExampleGiven a matrix[ [1,2],
2015-10-06 21:50:43
684
原创 Delete Digits
Given string A representative a positive integer which has N digits, remove any k digits of the number, the remaining digits are arranged according to the original order to become a new positive integ
2015-09-07 20:20:05
577
原创 Continuous Subarray Sum II
Given an integer array, find a continuous rotate subarray where the sum of numbers is the biggest. Your code should return the index of the first number and the index of the last number. (If their are
2015-09-01 10:35:53
703
原创 Best Time to Buy and Sell Stock III
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most twotransactions.Have you met t
2015-08-24 22:30:37
446
原创 Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe
2015-08-24 20:24:55
499
原创 strStr
strstr (a.k.a find sub string), is a useful function in string operation. Your task is to implement this function.For a given source string and a target string, you should output the firstindex(fr
2015-08-12 18:50:21
1193
原创 Product of Array Exclude Itself
Given an integers array A.Define B[i] = A[0] * ... * A[i-1] * A[i+1] * ... * A[n-1], calculate B WITHOUT divide operation.Have you met this question in a real interview? YesExamp
2015-08-09 15:35:00
480
原创 Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.Have you met this question in a real interview? YesExamp
2015-08-09 15:14:54
423
原创 Recover Rotated Sorted Array
Given a rotated sorted array, recover it to sorted array in-place.Have you met this question in a real interview? YesExample[4, 5, 1, 2, 3] -> [1, 2, 3, 4, 5]Challenge
2015-08-05 15:49:29
451
原创 Flip Bits
Determine the number of bits required to flip if you want to convert integer n to integer m.Have you met this question in a real interview? YesExampleGiven n = 31 (11111), m = 14
2015-08-05 14:49:47
808
原创 Subtree
You have two every large binary trees: T1, with millions of nodes, and T2, with hundreds of nodes. Create an algorithm to decide if T2 is a subtree of T1.Have you met this question in a real
2015-08-05 11:15:43
560
原创 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.此
2015-08-02 15:59:48
333
原创 Remove Duplicates from Sorted Array
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 for another array, you must do this in place with
2015-08-02 15:23:46
341
原创 Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is
2015-08-02 14:40:40
441
原创 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. Y
2015-08-02 10:43:45
449
原创 Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.类似于归并排序的处理,这里将一个个链表看成一个个有序的元素。/** * Definition for singly-linked list. * struct ListNode { *
2015-08-02 10:29:26
323
原创 Generate Parentheses
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-08-02 09:49:00
342
原创 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-08-01 22:28:19
451
原创 3Sum Closest
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. You may assume that each input would have exact
2015-08-01 22:07:19
321
原创 3Sum
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 zero.Note:Elements in a triplet (a,b,c
2015-08-01 21:25:24
409
原创 Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.求解最长公共前缀,看到第一反应是用trie树,简历一颗trie树,然后查找下,某个点的计数次数是不是等于len,不等于则停止,等于则加入公共前缀字符串,继续查找。class TrieNode {public:
2015-08-01 18:46:43
349
原创 Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.和整数转罗马数字一样,根据转换规则转换。class Solution {public: //分析最近的两个字符,如果i字符比i-1字符小,那么此时应该是s
2015-08-01 18:09:33
316
原创 Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.此题找规律模拟操作,分析1-10的整数是如何构造出罗马数字的,然后再依葫芦画瓢,注意细节的处理。class Solution {public: string In
2015-08-01 17:54:11
326
原创 Container With Most Water
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 endpoints of line i is at (i, ai) and (i, 0). Fin
2015-08-01 17:34:54
307
原创 Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of convertin
2015-08-01 17:15:05
322
原创 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-08-01 17:07:46
498
原创 Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321对于数值问题,首先一定要记住,一定要时刻注意溢出问题,这个题目不难,就是要注意对于x >= INT_MAX 或者 x class Solution {public: //边求每一位,边反转
2015-08-01 16:35:20
386
原创 ZigZag Conversion
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-08-01 16:24:55
278
原创 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. 题目最暴力的方法是,枚举字
2015-08-01 16:06:33
346
原创 Longest Substring Without Repeating Characters
Given 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 the length is 3. Fo
2015-07-31 15:52:03
395
原创 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, whe
2015-07-31 14:56:51
277
原创 Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link
2015-07-31 14:48:04
377
原创 Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).中位数是第K个数,K = (m + n)/2,,不
2015-07-31 10:51:37
345
原创 Jump Game II
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.Your goal i
2015-07-29 10:57:22
293
原创 Course Schedule
There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as
2015-07-17 00:02:16
330
原创 Number of Digit One
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6, because digit 1 occurred in the follow
2015-07-16 16:29:40
474
原创 Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to
2015-07-07 22:55:09
329
原创 Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order
2015-06-21 20:37:07
447
原创 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-05-15 17:21:12
357
原创 Subsets II
Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain du
2015-05-15 16:42:23
572
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人