上一页 1 ··· 8 9 10 11 12 13 14 下一页
摘要: Given two wordsword1andword2, find the minimum number of steps required to convertword1toword2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:a) Insert a characterb) Delete a characterc) Replace a characterclass Solution { public: int minDistance(s... 阅读全文
posted @ 2013-01-08 07:25 西施豆腐渣 阅读(142) 评论(0) 推荐(0) 编辑
摘要: A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given an encoded message containing digits, determine the total number of ways to decode it.For example,Given encoded message"12", it 阅读全文
posted @ 2013-01-08 04:17 西施豆腐渣 阅读(167) 评论(0) 推荐(0) 编辑
摘要: Divide two integers without using multiplication, division and mod operator.public class Solution { public int divide(int divid, int divis) { // Start typing your Java solution below // DO NOT write main() function long dividend = divid; long divisor = divis; boolean sign = false;... 阅读全文
posted @ 2013-01-07 22:41 西施豆腐渣 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 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 complete at mosttwotransactions.Note:You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).key points: 阅读全文
posted @ 2012-12-27 00:54 西施豆腐渣 阅读(128) 评论(0) 推荐(0) 编辑
摘要: Flatten Binary Tree to Linked ListOct 14 '12Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5... 阅读全文
posted @ 2012-12-25 01:36 西施豆腐渣 阅读(109) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algorithm should use only constant space. You maynotmodify the values in the list, only nodes itself can be changed.keypoints:1, head is 阅读全文
posted @ 2012-12-25 00:11 西施豆腐渣 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 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 3 But the following is not: 1 / \ 2 2 \ \ 3 3 Note:Bonus points if you could solve it both recursively a... 阅读全文
posted @ 2012-12-24 23:32 西施豆腐渣 阅读(107) 评论(0) 推荐(0) 编辑
摘要: Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.For example,Given input array A =[1,1,2],Your function should return length =2, and A is 阅读全文
posted @ 2012-12-24 07:47 西施豆腐渣 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 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 N A P L S I I G Y I R And then read line by line:"PAHNAPLSIIGYIR"Write the code that will take a string 阅读全文
posted @ 2012-12-24 07:36 西施豆腐渣 阅读(130) 评论(0) 推荐(0) 编辑
摘要: Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should run inO(n) time and uses constant space.incomplete.class Solution { public: int firstMissingPositive(int A[], int n) { // Start typing your ... 阅读全文
posted @ 2012-12-22 13:42 西施豆腐渣 阅读(122) 评论(0) 推荐(0) 编辑
上一页 1 ··· 8 9 10 11 12 13 14 下一页