上一页 1 2 3 4 5 6 7 8 9 ··· 11 下一页
摘要: Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word: a) Insert a character b) Delete a character c) Replace a character思路:普通的DP很好写,问题是路径压缩的DP压缩如果进行,空间如何重复利用 阅读全文
posted @ 2013-07-10 21:41 一只会思考的猪 阅读(153) 评论(0) 推荐(0) 编辑
摘要: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.思路:完全的in-place,利用了第一次出现0位置的第i行和第j列存储将来可能出现0的行的下标和列的下标class Solution {public: void setZeroes(vector > &matrix) { // Start typing your C/C++ solution below // DO NOT write int main() function ... 阅读全文
posted @ 2013-07-10 21:18 一只会思考的猪 阅读(187) 评论(0) 推荐(0) 编辑
摘要: Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each row is greater than the last integer of the previous row.For example,Consider the following matrix:[ [1, .. 阅读全文
posted @ 2013-07-10 04:36 一只会思考的猪 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 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 0, 1, and 2 to represent the color red, white, and blue respectively. Note: You are not suppose to use t 阅读全文
posted @ 2013-07-10 04:28 一只会思考的猪 阅读(227) 评论(0) 推荐(0) 编辑
摘要: Given two integersnandk, return all possible combinations ofknumbers out of 1 ...n.For example,Ifn= 4 andk= 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]class Solution {public: void dfs(vector> &ans, vector path,int n, int k, int ok_n){ if (ok_n == k){ ans.... 阅读全文
posted @ 2013-07-10 03:59 一只会思考的猪 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 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 to hold additional elements from B. The number of elements initialized in A and B are m and n respectively.class Solution {public: void merge(int A[], int m, int B[], int n) {... 阅读全文
posted @ 2013-07-09 21:58 一只会思考的猪 阅读(139) 评论(0) 推荐(0) 编辑
摘要: Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL. Note: Given m, n satisfy the following condition: 1 ? m ? n ? length of list.class Solution {public: void rev 阅读全文
posted @ 2013-07-09 21:47 一只会思考的猪 阅读(164) 评论(0) 推荐(0) 编辑
摘要: Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For example, Given sorted array A = [1,1,1,2,2,3], Your function should return length = 5, and A is now [1,1,2,2,3].class Solution {public: int removeDuplicates(int A[], int n) { // Start typing your C/C++ sol 阅读全文
posted @ 2013-07-09 21:07 一只会思考的猪 阅读(113) 评论(0) 推荐(0) 编辑
摘要: 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.Given 1->1->1->2->3, return 2->3.class Solution {public: ListNode *deleteDuplica 阅读全文
posted @ 2013-07-09 20:24 一只会思考的猪 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 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 {public: ListNode *deleteDuplicates(ListNode *head) { // Start typing your C/C++ solution 阅读全文
posted @ 2013-07-08 08:28 一只会思考的猪 阅读(115) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 ··· 11 下一页