字符串
PKU_CXK
北京大学信息科学技术学院
展开
-
POJ 2752: Seek the Name, Seek the Fame(简单KMP-NEXT数组的应用)
题意大概就是给你一个很长的字符串,然后让你找所有满足”前缀=后缀”的长度.很显然,使用KMP里的求解NEXT数组的思想.最长的是串的长度,假设为len这里将next数组做一个变形,让next[i] = next[i+1],那么,第二长的长度就是next[len-1].通过举例子可以发现,这是个不断迭代的过程,第三长的是next[ next[len-1] -1 ],最后直到next[t]<1时迭代结束原创 2016-12-16 14:16:00 · 388 阅读 · 0 评论 -
LeetCode | 36. Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’. A partially filled sudoku whi原创 2017-06-05 20:59:07 · 310 阅读 · 0 评论 -
LeetCode | 38. Count and Say
The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as “one 1” or 11. 11 is read off as “t原创 2017-06-10 18:33:49 · 230 阅读 · 0 评论 -
POJ 1001:Exponentiation —— 高精度浮点数运算
总时间限制: 500ms 内存限制: 65536kB 描述 Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experi原创 2017-07-08 11:02:29 · 802 阅读 · 0 评论 -
LeetCode | 65. Valid Number
Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to be ambiguous. You should g原创 2017-07-25 09:57:10 · 411 阅读 · 0 评论 -
LeetCode | 67. Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".思路:大整数加法,二进制class Solution {public: string addBinary(string a, string b) { int原创 2017-07-25 10:25:09 · 277 阅读 · 0 评论 -
LeetCode | 71. Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"Corner Cases:Did you consider the case where path = "/../"?In thi原创 2017-08-03 01:39:33 · 326 阅读 · 0 评论 -
LeetCode | 76. Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BANC".Note: If原创 2017-09-05 13:35:33 · 254 阅读 · 0 评论 -
KMP 算法的应用
KMP算法的应用主要体现在Next数组的计算方式上。Next数组含义如下: Next[i] = j, 表示下标 i 之前连续 j 个字符,和字符串开始的连续 j 个字符相同。这会带来很多应用。比如1、POJ 2406:字符串乘方#include <iostream>#include <algorithm>#include <string>#i...原创 2018-07-10 23:59:31 · 1419 阅读 · 0 评论 -
POJ 数据结构与算法A 0407:去除C程序中的注释
http://dsa.openjudge.cn/string/0407/ 直接贴代码,注释说明的很详细。#include <iostream>#include <algorithm>#include <string>#include <cstring>#include <cstdio>#include <vect...原创 2018-07-11 00:39:45 · 947 阅读 · 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。暴力算法,6MS ACclass Solution {public: int strStr(string haystack, string原创 2017-05-24 15:44:33 · 337 阅读 · 2 评论 -
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 “()”, which has原创 2017-05-26 23:38:09 · 352 阅读 · 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:Digit string "23"原创 2017-04-17 15:05:26 · 285 阅读 · 0 评论 -
后缀树(转)
后缀树 在《字符串匹配算法》一文中,我们熟悉了字符串匹配问题的形式定义:文本(Text)是一个长度为 n 的数组 T[1..n];模式(Pattern)是一个长度为 m 且 m≤n 的数组 P[1..m];T 和 P 中的元素都属于有限的字母表 Σ 表;如果 0≤s≤n-m,并且 T[s+1..s+m] = P[1.转载 2016-12-30 12:01:47 · 425 阅读 · 0 评论 -
POJ 1785 : Binary Search Heap Construction
描述 Read the statement of problem G for the definitions concerning trees. In the following we define the basic terminology of heaps. A heap is a tree whose internal nodes have each assigned a pr原创 2016-12-20 21:12:05 · 560 阅读 · 0 评论 -
POJ 2001 : Shortest Prefixes (字典树)
题意 : 给你一些字符串,让你为每个字符串找一个最短的前缀,来唯一标识这个字符串,与其他字符串区别开来.这个标志串不能是其他字符串的前缀,除非这个标志串等于这个字符串本身.考虑用字典树来做.标志当前位是否是结尾位,作为一个边界条件.先将所有字符串按长度排序,每次对一个字符串按位插入字典树里,将路过的位置num加1.最后,如果当前位的num是1,说明到当前位为止的前缀可以唯一标志这个字符串,保存这个原创 2016-12-21 00:04:25 · 429 阅读 · 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.了解罗马数字构造规则即可class Solution {public: string intToRoman(int num) { s原创 2017-04-08 17:41:28 · 227 阅读 · 0 评论 -
LeetCode | 14. Longest Common Prefix(最长公共前缀)
Write a function to find the longest common prefix string amongst an array of strings.解题思路一: 直接两两比较,遍历//6 ms Acceptedclass Solution {public: string longestCommonPrefix(vector<string>& strs) {原创 2017-04-10 16:09:06 · 281 阅读 · 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 answer.Example:Input: "原创 2017-04-02 02:36:15 · 310 阅读 · 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 P L S I I GY原创 2017-04-03 01:21:35 · 510 阅读 · 0 评论 -
LeetCode | 51.N-Queens
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.Each solut原创 2017-04-03 15:59:13 · 266 阅读 · 0 评论 -
LeetCode | 8.String to Integer (atoi)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases.N原创 2017-04-04 15:01:08 · 334 阅读 · 0 评论 -
LeetCode 97. Interleaving String
https://leetcode.com/problems/interleaving-string/DescriptionGiven s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.Example 1:Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbc...原创 2019-02-16 17:45:49 · 186 阅读 · 0 评论