摘要:
题意简述:求两个字符串的最长公共子序列的长度思路:最经典的最长公共子序列的长度(LCS问题)。动态转移方程如下:字符串X和字符串Y,dp[i][j]表示的是X的前i个字符和Y的前j个字符的最长公共子序列长度。如果 X[i]==Y[j],那么新的LCS+1;如果X[i]!=Y[j],则分别考察dp[i... 阅读全文
摘要:
next数组用于存储模式串中元素为j位置的最大重叠度。//KMP算法实现字符串匹配 //#include #include using namespace std; void compute_next(int* next,char const*p,int len){ int j=0; ... 阅读全文
摘要:
Problem: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->... 阅读全文
摘要:
problem: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. ... 阅读全文
摘要:
problem: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 is 1 -> 2... 阅读全文
摘要:
Problem:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?思路:顺时针方... 阅读全文
摘要:
problem:Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.思路解析:使用hashmap来存储已排好序的字符串。注意i... 阅读全文
摘要:
Problems:Given an array of integers, every element appears three times except for one. Find that single one. Note:Your algorithm should have a linear ... 阅读全文
摘要:
Problems:Given an array of integers, every element appears twice except for one. Find that single one. Note:Your algorithm should have a linear runtim... 阅读全文
摘要:
Problem:Write a function to find the longest common prefix string amongst an array of strings.Solution:题意要求求取字符串数组的最长公共前缀子串。从位置0开始,对每一个位置比较所有的字符串,直到遇到... 阅读全文