
IT公司面试习题
文章平均质量分 81
魔豆Magicbean
这个作者很懒,什么都没留下…
展开
-
[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],原创 2017-02-04 15:05:35 · 419 阅读 · 0 评论 -
[Leetcode] 78. Subsets 解题报告
题目:Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,3], a solution is:[ [3原创 2017-02-04 15:33:26 · 329 阅读 · 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 v原创 2017-02-04 16:08:50 · 422 阅读 · 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原创 2017-02-04 16:33:58 · 347 阅读 · 0 评论 -
[Leetcode] 61. Rotate List 解题报告
题目:Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.思路:最正统的解法就是two pointers:定义两个原创 2017-01-17 13:52:12 · 379 阅读 · 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原创 2017-01-17 14:20:54 · 480 阅读 · 0 评论 -
[Leetcode] 81. Search 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?Suppose an array sorted in ascending order is原创 2017-02-09 09:21:53 · 479 阅读 · 0 评论 -
[Leetcode] 82. Remove Duplicates from Sorted List II 解题报告
题目:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Gi原创 2017-02-09 09:47:59 · 368 阅读 · 0 评论 -
[Leetcode] 1. Two Sum 解题报告
题目: Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example:Given num...原创 2016-12-07 11:15:29 · 659 阅读 · 0 评论 -
[Leetcode] 2. 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 a...原创 2016-12-07 23:44:05 · 561 阅读 · 0 评论 -
[Leetcode] 3. Longest Substring without Repeating Characters 解题报告
题目: Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "...原创 2016-12-08 04:38:56 · 451 阅读 · 0 评论 -
[Leetcode] 4. Median of Two Sorted Arrays 解题报告
题目:思路:代码:原创 2016-12-08 05:06:56 · 730 阅读 · 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.Example:Input: "babad"Output: "bab"Note: "aba" is also a valid answ原创 2016-12-08 11:58:28 · 540 阅读 · 0 评论 -
[Leetcode] 6. 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原创 2016-12-08 23:21:57 · 546 阅读 · 0 评论 -
[Leetcode] 7. Reverse Integer 解题报告
题目:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321思路: 这类特别简单的题目对大多数面试者而言,都能够有清晰的思路并进而写出相应的代码。那么区分度在哪里呢?就在于你对特殊情况的考虑和处理,以及你编写程序的严谨性。对于原创 2016-12-10 04:33:25 · 466 阅读 · 0 评论 -
[Leetcode] 9. Palindrome Number 解题报告
题目:Determine whether an integer is a palindrome. Do this without extra space.思路: 题目不难,但仍然有三点需要特别注意: 1)如果是负数怎么办?假定如果是负数就返回false。 2)如果你想首先把整数转化为字符串,然后比较字符串是否是回文,那么需要考虑到此原创 2016-12-10 23:33:48 · 486 阅读 · 0 评论 -
[Leetcode] 10. Regular Expression Matching 解题报告
题目:Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire原创 2016-12-10 23:47:24 · 1260 阅读 · 0 评论 -
[Leetcode] 11. 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原创 2016-12-11 10:36:12 · 336 阅读 · 0 评论 -
[Leetcode] 12. Integer to Roman 解题报告
题目:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.思路:首先熟悉一下罗马数字的的对应符号(以下内容参考小榕流光的博客,在此表示感谢):I (1)V(5)X(10) L(50)C(100)D(5原创 2016-12-12 05:17:35 · 334 阅读 · 0 评论 -
[Leetcode] 13. Roman to Integer 解题报告
题目:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.思路: 可以看作是Leetcode 12的孪生题目,但是难度却比上一道题目低不少。通过上一道题目的分析可知,在该题目中只需要判断罗马数字原创 2016-12-12 05:44:35 · 340 阅读 · 0 评论 -
[Leetcode] 14. Longest Common Prefix 解题报告
题目:Write a function to find the longest common prefix string amongst an array of strings.思路: 也是easy级别的题目。对这种难度的题目来说,优秀的程序员的功底就体现在如何把代码写的简洁优雅(自己原来写的代码将近30行,太low了)。代码:class Solution {原创 2016-12-12 10:38:17 · 397 阅读 · 0 评论 -
[Leetcode] 15. 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: The solution set must no原创 2016-12-12 10:46:55 · 410 阅读 · 0 评论 -
[Leetcode] 16. 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 hav原创 2016-12-13 00:57:49 · 324 阅读 · 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原创 2016-12-13 01:02:03 · 408 阅读 · 0 评论 -
[Leetcode] 18. 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: The原创 2016-12-13 04:14:27 · 372 阅读 · 0 评论 -
[Leetcode] 19. 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原创 2016-12-13 04:51:37 · 322 阅读 · 0 评论 -
[Leetcode] 20. 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原创 2016-12-13 05:08:03 · 346 阅读 · 0 评论 -
[Leetcode] 21. 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.思路: Easy级别的题目,没有特别的技巧。还是那句老话,在链表处理中如果能加一个原创 2016-12-13 23:00:14 · 298 阅读 · 0 评论 -
[Leetcode] 22. 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:[ "((()))", "(()())", "(())()",原创 2016-12-13 23:14:53 · 342 阅读 · 0 评论 -
[Leetcode] 23. Merge k Sorted Lists 解题报告
题目:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路: 可以认为是Leetcode 21 Merge Two Sorted List的推广,其思路还是大同小异的,即每次从k个链表中找出头结点最小的那一个,加入到合原创 2016-12-13 23:29:04 · 428 阅读 · 0 评论 -
[Leetcode] 24. 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原创 2016-12-14 03:07:13 · 489 阅读 · 0 评论 -
[Leetcode] 25. 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原创 2016-12-14 03:11:33 · 632 阅读 · 0 评论 -
[Leetcode] 26. 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 p原创 2016-12-14 22:57:25 · 392 阅读 · 0 评论 -
[Leetcode] 27. Remove Element 解题报告
题目:Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constan原创 2016-12-14 23:07:29 · 406 阅读 · 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.思路:1、暴力枚举法:从haystack的开头试图匹配,如果匹配完成则返回;否则移动到下一位,并从needle的头部重原创 2016-12-15 09:09:04 · 456 阅读 · 0 评论 -
[Leetcode] 29. Divide Two Integers 解题报告
题目:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.思路: 我们在这里总结一下两种可能的思路(只考虑被除数和除数均为正数的情况):1、只要被除数大于等于除数,就从被除数中减去除数,原创 2016-12-15 09:28:19 · 835 阅读 · 0 评论 -
[Leetcode] 30. Substring with Concatenation of All Words 解题报告
题目:You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly原创 2016-12-17 00:03:06 · 349 阅读 · 0 评论 -
[Leetcode] 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原创 2016-12-17 00:37:17 · 719 阅读 · 0 评论 -
[Leetcode] 32. Longest Valid Parentheses 解题报告
题目:Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is原创 2016-12-18 00:48:31 · 832 阅读 · 0 评论 -
[Leetcode] 33. 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 ar原创 2016-12-28 00:46:52 · 979 阅读 · 0 评论