字符串处理
dxx707099957
这个作者很懒,什么都没留下…
展开
-
811. Subdomain Visit Count
A website domain like "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "leetcode.com", and at the lowest level, "discuss.leetcode.com"...原创 2018-04-09 11:04:59 · 283 阅读 · 0 评论 -
28. Implement strStr()
Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2Example 2:Input:...原创 2018-06-21 16:16:55 · 90 阅读 · 0 评论 -
58. Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is defined a...原创 2018-06-15 09:48:58 · 75 阅读 · 0 评论 -
125. Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Note: For the purpose of this problem, we define empty string as valid palindrome.Example 1...原创 2018-06-25 10:52:52 · 80 阅读 · 0 评论 -
537. Complex Number Multiplication(string流)
Given two strings representing two complex numbers.You need to return a string representing their multiplication. Note i2 = -1 according to the definition.Example 1:Input: "1+1i", "1+1i"Output: "0+2i...原创 2018-06-25 21:59:23 · 388 阅读 · 0 评论 -
553. Optimal Division
Given a list of positive integers, the adjacent integers will perform the float division. For example, [2,3,4] -> 2 / 3 / 4.However, you can add any number of parenthesis at any position to change ...原创 2018-06-26 11:26:42 · 93 阅读 · 0 评论 -
647.回文子串
给定一个字符串,你的任务是计算这个字符串中有多少个回文子串。具有不同开始位置或结束位置的子串,即使是由相同的字符组成,也会被计为是不同的子串。示例 1:输入: "abc"输出: 3解释: 三个回文子串: "a", "b", "c".示例 2:输入: "aaa"输出: 6说明: 6个回文子串: "a", "a", "a"原创 2018-06-26 17:17:25 · 93 阅读 · 0 评论 -
686. Repeated String Match
Given two strings A and B, find the minimum number of times A has to be repeated such that B is a substring of it. If no such solution, return -1.For example, with A = "abcd" and B = "cdabcdab".Return...原创 2018-06-20 14:51:26 · 93 阅读 · 0 评论 -
14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string "".Example 1:Input: ["flower","flow","flight"]Output: "fl"E...原创 2018-06-20 17:32:18 · 87 阅读 · 0 评论 -
709. 转换成小写字母
实现函数 ToLowerCase(),该函数接收一个字符串参数 str,并将该字符串中的大写字母转换成小写字母,之后返回新的字符串。 示例 1:输入: "Hello"输出: "hello"示例 2:输入: "here"输出: "here"示例 3:输入: "LOVELY"输出: "lovely"解题思路:使用lower函数转换为小写字母c原创 2018-08-06 09:54:09 · 139 阅读 · 0 评论 -
888. 公平的糖果交换(string流)
爱丽丝和鲍勃有不同大小的糖果棒:A[i] 是爱丽丝拥有的第 i 块糖的大小,B[j] 是鲍勃拥有的第 j 块糖的大小。因为他们是朋友,所以他们想交换一个糖果棒,这样交换后,他们都有相同的糖果总量。(一个人拥有的糖果总量是他们拥有的糖果棒大小的总和。)返回一个整数数组 ans,其中 ans[0] 是爱丽丝必须交换的糖果棒的大小,ans[1] 是 Bob 必须交换的糖果棒的大小。如果有多个...原创 2018-08-14 15:59:53 · 360 阅读 · 0 评论 -
784. 字母大小写全排列
给定一个字符串S,通过将字符串S中的每个字母转变大小写,我们可以获得一个新的字符串。返回所有可能得到的字符串集合。示例:输入: S = "a1b2"输出: ["a1b2", "a1B2", "A1b2", "A1B2"]输入: S = "3z4"输出: ["3z4", "3Z4"]输入: S = "12345"原创 2018-09-04 21:04:19 · 594 阅读 · 0 评论 -
389. 找不同 (异或运算)
给定两个字符串 s 和 t,它们只包含小写字母。字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。请找出在 t 中被添加的字母。 示例:输入:s = "abcd"t = "abcde"输出:e解释:'e' 是那个被添加的字母。解题思路:通过异或运算,找到s+t中唯一出现过一次的字符class Solution {public:...原创 2018-09-05 16:41:37 · 489 阅读 · 1 评论 -
38. 报数
报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数。其前五项如下:1. 12. 113. 214. 12115. 1112211 被读作 "one 1" ("一个一") , 即 11。11 被读作 "two 1s" ("两个一"), 即 21。21 被读作 "one 2", "one 1" ("一个原创 2018-10-18 10:10:56 · 85 阅读 · 0 评论 -
49. 字母异位词分组
给定一个字符串数组,将字母异位词组合在一起。字母异位词指字母相同,但排列不同的字符串。示例:输入: ["eat", "tea", "tan", "ate", "nat", "bat"],输出:[ ["ate","eat","tea"], ["nat","tan"],原创 2018-11-19 21:53:30 · 82 阅读 · 0 评论 -
345. Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Given s = "hello", return "holle".Example 2:Given s = "leetcode", return "leotcede".Note:The vowels does...原创 2018-05-28 21:44:16 · 98 阅读 · 0 评论 -
20. Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of brack...原创 2018-06-03 22:15:24 · 92 阅读 · 0 评论 -
541. Reverse String II
Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of them...原创 2018-05-14 22:22:13 · 95 阅读 · 0 评论 -
806. Number of Lines To Write String
We are to write the letters of a given string S, from left to right into lines. Each line has maximum width 100 units, and if writing a letter would cause the width of the line to exceed 100 units, it...原创 2018-04-04 09:54:02 · 161 阅读 · 0 评论 -
804. Unique Morse Code Words
International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a"maps to ".-", "b" maps to "-...", "c" maps to "-.-.", and so on.For原创 2018-04-03 17:07:48 · 125 阅读 · 0 评论 -
344. Reverse String
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".解题思路:字符串翻转,字符交换class Solution {public: string reverseString(string s) { ...原创 2018-03-21 16:37:14 · 106 阅读 · 0 评论 -
796. Rotate String
We are given two strings, A and B.A shift on A consists of taking string A and moving the leftmost character to the rightmost position. For example, if A = 'abcde', then it will be 'bcdea' after one s...原创 2018-03-20 21:34:38 · 105 阅读 · 0 评论 -
771. Jewels and Stones
You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in Sis a type of stone you have. You want to know how many of the ston...原创 2018-02-01 14:52:27 · 281 阅读 · 0 评论 -
557. Reverse Words in a String III
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Input: "Let's take LeetCode contest"Outpu...原创 2018-04-09 11:37:19 · 91 阅读 · 0 评论 -
500. Keyboard Row
Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below.Example 1:Input: ["Hello", "Alaska", "Dad", "Peace"]Out...原创 2018-04-10 21:18:04 · 108 阅读 · 0 评论 -
520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not.We define the usage of capitals in a word to be right when one of the following cases holds:All letters in this word...原创 2018-04-12 22:29:40 · 96 阅读 · 0 评论 -
13. Roman to Integer
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D 5...原创 2018-05-03 20:59:41 · 113 阅读 · 0 评论 -
383. Ransom Note
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; ot...原创 2018-05-04 09:06:26 · 203 阅读 · 0 评论 -
387. First Unique Character in a String
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.Examples:s = "leetcode"return 0.s = "loveleetcode",return 2.Note: You may assume...原创 2018-05-04 09:17:09 · 89 阅读 · 0 评论 -
551. Student Attendance Record I
You are given a string representing an attendance record for a student. The record only contains the following three characters:'A' : Absent.'L' : Late.'P' : Present.A student could be rewarded if his...原创 2018-05-04 10:37:57 · 100 阅读 · 0 评论 -
C/C++ 学习笔记:istringstream、ostringstream、stringstream 类介绍 和 stringstream类 clear函数的真正用途
0、C++的输入输出分为三种:(1)基于控制台的I/O (2)基于文件的I/O (3)基于字符串的I/O 1、头文件[cpp] view plaincopyprint?#include <sstream> 2、作用istringstream类用于执行C++风格的字符串流的输入操作。 ostringstream类用于执行C++风格的字符串流的输出操...转载 2018-05-14 21:35:47 · 185 阅读 · 0 评论 -
824. Goat Latin
A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only.We would like to convert the sentence to "Goat Latin" (a made-up language simil...原创 2018-05-14 22:11:53 · 304 阅读 · 0 评论 -
ASCII可显示字符
二进制 十进制 十六进制 图形 0010 0000 32 20 (空格)(␠) 0010 0001 33 21 ! 0010 0010 34 22 " 0010 0011 35 23...原创 2018-12-10 16:07:14 · 215 阅读 · 0 评论