Leetcode
majunyangyang
这个作者很懒,什么都没留下…
展开
-
IOS/MAC环境下thrift的安装
本文参考博文:http://blog.csdn.net/yohunl/article/details/417485111、安装brew,安装过的可以sudo brew update一下。2、用brew安装thrift,sudo brew install thrift或者brew install thrift。3、建立链接,brew link thrift。4、如果3中出现link失原创 2015-07-09 10:17:10 · 511 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.题意是在一个字符串中查找目标字符串的第一个位置,如果没有返回-1。这道题虽然题意很简单,但是细节较多,需要考虑目标字符串为空的情原创 2014-12-08 09:20:27 · 315 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-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原创 2014-12-23 10:30:30 · 376 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.class Solution {pu原创 2014-12-08 14:44:21 · 349 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?不说多了,斐波那契函数!class Soluti原创 2014-12-08 11:48:30 · 354 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-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.c原创 2014-12-07 17:45:47 · 281 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Element原创 2014-12-23 09:34:09 · 254 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-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-01-12 17:12:51 · 274 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-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原创 2014-12-07 15:08:20 · 309 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.class Solution {publi原创 2014-12-07 20:51:22 · 402 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-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原创 2014-12-07 17:24:28 · 255 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Valid Parentheses
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 va原创 2014-12-07 16:00:10 · 288 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element原创 2014-12-24 09:46:33 · 262 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 特殊测试用原创 2015-01-24 10:51:48 · 405 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-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-01-24 10:29:29 · 357 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Best Time to Buy and Sell Stock II
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 as many transactions as you like (ie, buy on原创 2014-12-15 10:52:48 · 339 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),原创 2014-12-15 10:17:13 · 286 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Compare Version Numbers
Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and co原创 2014-12-25 09:44:02 · 389 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is原创 2014-12-09 09:19:02 · 361 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Insertion Sort List
Sort a linked list using insertion sort.本题采用的是新建一个头结点,向新建的头结点中插入新的元素功能测试用例:{ 0, 2, 5, 3, 6, 10}特殊输入测试用例:NULL, {0}class Solution {public: ListNode *insertionSortList(ListNode *head) { if原创 2014-12-09 17:29:54 · 387 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.本题并没有要求相关的回文字符串一定要放在一起,只需建立一个哈希表并对每个字符串排序后与哈希表里进行比较,就可以知道是否有变换字符串功能测试用例:"tr原创 2014-12-24 16:48:45 · 318 阅读 · 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.class Solution {public: ListNode *mergeTwoLists(List原创 2014-12-08 15:37:55 · 317 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille原创 2014-12-09 10:27:23 · 315 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Merge Sorted Array
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 (size that is greater or equal to m + n) to hold additional elements from原创 2014-12-07 16:44:22 · 282 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-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原创 2014-12-22 10:22:09 · 334 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-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原创 2014-12-22 14:21:58 · 299 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-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原创 2014-11-27 11:10:21 · 376 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20原创 2014-11-26 12:43:05 · 267 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7},原创 2014-11-26 12:45:56 · 337 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string, no原创 2014-11-21 09:26:29 · 534 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Sort Colors
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, white and blue.Here, we will use the integers原创 2014-11-20 10:34:13 · 369 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".原创 2014-11-19 09:03:49 · 387 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-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原创 2014-11-19 11:29:54 · 343 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).原创 2014-11-19 08:59:51 · 279 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.原创 2014-11-19 09:01:39 · 312 阅读 · 0 评论 -
插入排序,选择排序,递归排序和冒泡排序的实现
以下是算法导论中的几种排序方式,包括xuan'z原创 2014-11-16 11:24:49 · 376 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘原创 2014-11-30 11:46:11 · 316 阅读 · 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 number 123.Find the tota原创 2014-12-16 09:45:10 · 304 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.class Solution{public: int minD原创 2014-12-05 10:14:34 · 241 阅读 · 0 评论 -
和大神们学习每天一题(leetcode)-Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.class Solution{public: in原创 2014-12-05 10:03:01 · 188 阅读 · 0 评论