08 2015 档案
摘要:题目:Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:You may assume thatnums1has enough space (size that is gr...
阅读全文
摘要:题目:Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, r...
阅读全文
摘要:题目:You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you cl...
阅读全文
摘要:题目:Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".提示:此题我的第一反应是把输入的两个字符串转化为数字,相加以后再把结果转化为二进制输出,...
阅读全文
摘要:题目:Given a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word ...
阅读全文
摘要:题目:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.提示:此题可以使用暴力搜索方法。当然也可以使用...
阅读全文
摘要:题目:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as...
阅读全文
摘要:题目: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 ...
阅读全文
摘要:题目:Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra space fo...
阅读全文
摘要:题目: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.提示:此题其...
阅读全文
摘要:题目:Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the corre...
阅读全文
摘要:题目: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...
阅读全文
摘要:题目:Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After...
阅读全文
摘要:题目:Write a function to find the longest common prefix string amongst an array of strings.代码:class Solution {public: string longestCommonPrefix(vect...
阅读全文
摘要:题目:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.提示:此题只要熟悉罗马数字的书写语法,做起来就不会太难,关于罗马数字的介绍可以参考...
阅读全文
摘要:题目: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...
阅读全文
摘要:题目:Determine whether an integer is a palindrome. Do this without extra space.提示:此题需要注意负数不是回文数。另外,我一开始的思路是把输入数字通过整除和取模运算把它倒转过来与原数字进行比较(不用考虑倒转过来的数字会不会溢出...
阅读全文
摘要:题目:Implementatoito convert a string to an integer.Hint:Carefully consider all possible input cases. If you want a challenge, please do not see below a...
阅读全文
摘要:题目:Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321Have you thought about this?Here are some good questions to ...
阅读全文
摘要:题目:Given an array of sizen, find the majority element. The majority element is the element that appears more than⌊ n/2 ⌋times.You may assume that the ...
阅读全文
摘要:题目:Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["...
阅读全文
摘要:题目:Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include2, 3, 5. For ex...
阅读全文
摘要:题目:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: P...
阅读全文
摘要:题目:Description:Count the number of prime numbers less than a non-negative number,n.提示:求素数个数的比较快速的方法是“埃拉托斯特尼筛法”,其原理很简单,具体的解释可以点击该链接。代码:一个简单的“埃拉托斯特尼筛法”实...
阅读全文
摘要:题目:Given an array of strings, group anagrams together.For example, given:["eat", "tea", "tan", "ate", "nat", "bat"],Return:[ ["ate", "eat","tea"], [...
阅读全文
摘要:题目:Given two stringssandt, determine if they are isomorphic.Two strings are isomorphic if the characters inscan be replaced to gett.All occurrences of...
阅读全文
摘要:题目:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep co...
阅读全文
摘要:题目:Determine if a Sudoku is valid, according to:Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled wi...
阅读全文
摘要:题目:Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive inte...
阅读全文
摘要:题目:Given two stringssandt, write a function to determine iftis an anagram ofs.For example,s= "anagram",t= "nagaram", return true.s= "rat",t= "car", re...
阅读全文
摘要:题目:Given an array of integers and an integerk, find out whether there are two distinct indicesiandjin the array such thatnums[i] = nums[j]and the diff...
阅读全文
摘要:题目:Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the ...
阅读全文
摘要:题目:Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].N...
阅读全文
摘要:题目:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next poi...
阅读全文
摘要:题目:Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3]....
阅读全文
摘要:题目:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?提示:首先,题目中要求'without using extra space',...
阅读全文
摘要:题目:Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26...
阅读全文
摘要:题目:Related to questionExcel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: ...
阅读全文
摘要:题目:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired byt...
阅读全文
摘要:题目:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wikipedi...
阅读全文
摘要:题目:Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as theHamming weight).For example, the 32-bit...
阅读全文
摘要:题目:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complet...
阅读全文
摘要:题目: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...
阅读全文
摘要:题目: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 is1 -> 2 -> 3 ...
阅读全文
摘要:题目:Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complex...
阅读全文
摘要:题目: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...
阅读全文
摘要:题目:Given a non-negative integernum, repeatedly add all its digits until the result has only one digit.For example:Givennum = 38, the process is like:3...
阅读全文
摘要:题目要求:Download the text filehere.The goal of this problem is to implement the "Median Maintenance" algorithm (covered in the Week 5 lecture on heap app...
阅读全文
摘要:题目要求:Download the text filehere. (Right click and save link as).The goal of this problem is to implement a variant of the 2-SUM algorithm (covered in ...
阅读全文