
面试题算法题
booirror
享受编程的乐趣
展开
-
LeetCode9——Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.题目大意判断一个int是否为回文数,不使用额外的储存空间。难度系数:容易实现int getfactor(int x) { if (x < 10) return 1; int facto原创 2015-01-27 10:26:54 · 3201 阅读 · 2 评论 -
LeetCode14——Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.题目大意写一个函数来找出所有字符串里最长的公共前缀。难度系数:容易实现题目不难,基本思路大家都能想到,就是一些细节可能会遗漏。这个也没啥好算法,不管怎样,都需要一个个去比较。 所以没啥好说原创 2015-01-27 17:58:51 · 806 阅读 · 0 评论 -
LeetCode125——Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a p原创 2015-01-27 18:05:48 · 3379 阅读 · 0 评论 -
LeetCode119——Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note: Could you optimize your algorithm to use only O(k) extra space?题目大意给定一个索引k,原创 2015-01-27 18:15:05 · 1225 阅读 · 0 评论 -
LeetCode13——Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.题目大意给你个罗马数字,把它转换成一个int数。输入限定在[1, 3999]。难度系数:容易实现一次性通过,:)int getVal(c原创 2015-01-27 17:51:09 · 3072 阅读 · 3 评论 -
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-01-26 18:06:22 · 1115 阅读 · 0 评论 -
LeetCode172——Factorial Trailing Zeroes
LeetCode172——Factorial Trailing ZeroesGiven an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.难度系数:容易题目大意:给定一个整数n,原创 2015-01-13 00:39:23 · 2832 阅读 · 0 评论 -
LeetCode112——Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example: Given the below binary tree and sum原创 2015-01-13 18:34:45 · 4394 阅读 · 14 评论 -
LeetCode88——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原创 2015-01-14 16:10:41 · 2088 阅读 · 0 评论 -
LeetCode20——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 valid原创 2015-01-14 12:58:18 · 1201 阅读 · 0 评论 -
LeetCode171——Excel Sheet Column Number
题目Given a column title as appear in an Excel sheet, return its corresponding column number.For example:A -> 1B -> 2C -> 3...Z -> 26AA -> 27AB -> 28 Credits: Special thanks to @ts f原创 2015-01-14 17:07:17 · 1067 阅读 · 0 评论 -
LeetCode168——Excel Sheet Column Title
LeetCode168——Excel Sheet Column Title题目Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example:1 -> A2 -> B3 -> C...26 -> Z27 -> AA2原创 2015-01-15 13:59:34 · 1261 阅读 · 0 评论 -
LeetCode169——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 al原创 2015-01-15 11:11:26 · 7130 阅读 · 0 评论 -
关于二叉树的一道面试题
刚看到一个题:给一个string of nested ternary operations例如a?b?c:d:e,build a tree:root是a,左子树是b?c:d对应的tree ,右子树是e。保证input都是valid的。嗯,先给自己挖个坑,暂时没空,先放着,感兴趣的也可以自己做一做(2015/1/27)原创 2015-01-27 18:41:17 · 801 阅读 · 0 评论 -
LeetCode165——Compare Version Numbers
题目Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 You may assume that the version strings are non-empty and contain only digits and the . cha原创 2015-01-16 15:43:12 · 3665 阅读 · 0 评论 -
LeetCode118——Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]题目大意给定numRows,生成帕斯卡三原创 2015-02-03 17:50:15 · 1564 阅读 · 0 评论 -
LeetCode111——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.之后发的文章就不翻译了,因为一般读这个文章的人都是刷LeetCode的人,读题目应该不成问题,我就不做多余的翻译了。难度系数:容易实现i原创 2015-02-05 15:23:26 · 2033 阅读 · 0 评论 -
LeetCode107——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}原创 2015-02-05 15:28:15 · 1198 阅读 · 0 评论 -
LeetCode100——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.难度系数:容原创 2015-02-05 15:35:08 · 722 阅读 · 0 评论 -
LeetCode104——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.难度系数:容易实现int maxDepth(Tr原创 2015-02-05 15:29:44 · 2012 阅读 · 0 评论 -
LeetCode19——Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the原创 2015-02-05 15:07:55 · 1604 阅读 · 0 评论 -
LeetCode110——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-02-05 15:26:00 · 1581 阅读 · 0 评论 -
LeetCode102——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原创 2015-02-05 15:31:46 · 1132 阅读 · 0 评论 -
LeetCode101——Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the follow原创 2015-02-05 15:33:35 · 999 阅读 · 0 评论 -
LeetCode160——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 ↘原创 2015-01-21 10:46:53 · 1302 阅读 · 0 评论 -
LeetCode26——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-02-11 15:16:43 · 1079 阅读 · 0 评论 -
LeetCode36——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 filled sudo原创 2015-02-11 15:32:21 · 1279 阅读 · 0 评论 -
LeetCode27——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-02-11 15:20:33 · 719 阅读 · 0 评论 -
LeetCode70——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?难度系数:容易实现int climb原创 2015-02-11 15:28:56 · 1625 阅读 · 0 评论 -
LeetCode21——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.难度系数:容易实现ListNode *mergeTwoLists(ListNode *l1原创 2015-02-11 17:19:57 · 1316 阅读 · 0 评论 -
LeetCode28——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-02-11 15:23:41 · 1121 阅读 · 0 评论 -
LeetCode66——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.难度系数:容易实现v原创 2015-02-11 15:30:34 · 1003 阅读 · 0 评论 -
LeetCode137——Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without u原创 2015-02-26 18:15:42 · 2078 阅读 · 0 评论 -
LeetCode155——Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get原创 2015-01-23 11:06:55 · 1281 阅读 · 0 评论 -
LeetCode173——Binary Search Tree Iterator
终于进入了中等难度的题目了。貌似leetcode不停地加题量,要做完正的是不那么容易啊。新年开工,小伙伴们都在晒红包,深圳这边 上班第一天一般都有发红包,不知道其他地方的是不是也这样。到目前为止,做了40题了,不得不感慨,算法有待提高。大学真是白过了,人生那么美好的四年白过了,这是多么的悲哀。 现在想想,一个人要想在大学过得有意义,对以后的人生打下坚实的基础,那么最迟在大学一年之后,一定要原创 2015-02-26 17:08:41 · 1369 阅读 · 0 评论 -
LeetCode58——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 d原创 2015-02-11 17:32:19 · 1451 阅读 · 0 评论 -
LeetCode83——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.难度系数:容易实现ListN原创 2015-02-11 15:19:02 · 840 阅读 · 0 评论 -
LeetCode67——Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".难度系数:容易实现string addBinary(string a, string b){ string sum; int原创 2015-02-11 16:37:51 · 1069 阅读 · 0 评论 -
LeetCode38——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 "one 2原创 2015-02-11 18:43:12 · 1473 阅读 · 0 评论 -
LeetCode6——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 I原创 2015-01-23 15:17:07 · 906 阅读 · 0 评论