String
文章平均质量分 72
flyatcmu
这个作者很懒,什么都没留下…
展开
-
Replace All ?‘s to Avoid Consecutive Repeating Characters
Given a stringscontaining only lower case English lettersand the '?'character, convertallthe '?' characters into lower case letters such that the final string does not contain anyconsecutive repeatingcharacters.Youcannotmodify the non '?' charac...原创 2020-09-06 13:03:49 · 151 阅读 · 0 评论 -
Break a Palindrome
Given a palindromic stringpalindrome, replaceexactly onecharacter by any lowercase English letter so that the string becomes the lexicographically smallest possible string thatisn'ta palindrome.After doing so, return the final string. If there is n...原创 2020-09-05 00:06:00 · 252 阅读 · 0 评论 -
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 3, because by repeating A three times (“abcdabcdabc原创 2020-07-13 03:59:27 · 146 阅读 · 1 评论 -
Palindrome Pairs
Given a list ofuniquewords, find all pairs ofdistinctindices(i, j)in the given list, so that the concatenation of the two words, i.e.words[i] + words[j]is a palindrome.Example 1:Input: ["abcd","dcba","lls","s","sssll"]Output: [[0,1],[1,0],[3,...原创 2020-06-21 12:46:15 · 266 阅读 · 0 评论 -
Validate IP Address
Write a function to check whether an input string is a valid IPv4 address or IPv6 address or neither.IPv4addresses are canonically represented in dot-decimal notation, which consists of four decimal numbers, each ranging from 0 to 255, separated by dots.原创 2020-06-14 02:31:54 · 345 阅读 · 0 评论 -
Custom Sort String
SandTare strings composed of lowercase letters. InS, no letter occurs more than once.Swas sorted in some custom order previously. We want to permute the characters ofTso that they match the order thatSwas sorted. More specifically, ifxoccurs b...原创 2020-06-07 01:44:56 · 184 阅读 · 0 评论 -
Goat Latin
A sentenceSis 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 similar to Pig Latin.)The rules of Goat Latin are as foll...原创 2020-05-30 13:56:54 · 205 阅读 · 0 评论 -
Shortest Palindrome
Given a strings, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.Example 1:Input: "aacecaaa"Output: "aaacecaaa"Example 2:.原创 2020-05-26 05:48:00 · 128 阅读 · 0 评论 -
Repeated Substring Pattern
Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase Engli...原创 2020-05-07 12:22:44 · 231 阅读 · 0 评论 -
Find And Replace in String
To some stringS, we will perform somereplacementoperations that replace groups of letters with new ones (not necessarily the same size).Each replacement operation has3parameters: a starting ind...原创 2020-05-06 11:33:51 · 172 阅读 · 0 评论 -
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...原创 2020-04-15 01:30:43 · 103 阅读 · 0 评论 -
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...原创 2020-04-14 11:52:02 · 107 阅读 · 0 评论 -
Remove Palindromic Subsequences
Given a stringsconsisting only ofletters'a'and'b'. In a single step you can remove onepalindromicsubsequencefroms.Return the minimum number of steps to make the given string empty.A stri...原创 2020-02-28 12:50:21 · 241 阅读 · 0 评论 -
Unique Email Address
思路1:面试的时候可以自己写process methodclass Solution { public int numUniqueEmails(String[] emails) { if(emails == null || emails.length == 0) { return 0; } HashSet&...原创 2020-02-10 14:54:56 · 242 阅读 · 0 评论 -
Backspace string compare
Given twostringsSandT,return if they are equal when both are typed into empty text editors.#means a backspace character.Example 1:Input: S = "ab#c", T = "ad#c"Output: trueExplanation: Bo...原创 2020-02-10 14:41:18 · 223 阅读 · 0 评论 -
License Key Formatting
You are given a license key represented as a string S which consists only alphanumeric character and dashes. The string is separated into N+1 groups by N dashes.Given a number K, we would want to re...原创 2020-02-10 14:33:54 · 251 阅读 · 0 评论 -
Rotate String II
Given a string(Given in the way of char array), a right offset and a left offset, rotate the string by offset in place.(left offest represents the offset of a string to the left,right offest represent...原创 2019-12-20 12:54:54 · 179 阅读 · 0 评论 -
max substring
Given a string s, return the last substring of s in lexicographical order.ExampleExample 1:Input: "abab"Output: "bab"Explanation: The substrings are ["a", "ab", "aba", "abab", "b", "ba", "bab...原创 2019-11-20 01:31:19 · 346 阅读 · 0 评论 -
Rotate String
Given a string(Given in the way of char array) and an offset, rotate the string by offsetin place. (rotate from left to right).ExampleExample 1:Input: str="abcdefg", offset = 3Output: str = "...原创 2019-10-27 02:19:41 · 233 阅读 · 0 评论 -
Strstr 两种算法
DescriptionImplementstrStrfunction in O(n + m) time.strStrreturn the first index of the target string in a source string. The length of the target string ismand the length of the source strin...原创 2019-10-19 12:55:02 · 239 阅读 · 0 评论 -
One Edit Distance
Given two strings S and T, determine if they are both one edit distance apart.思路:可以用edit distance 来计算最小值,但是time out现在用我看到的一种解法,recursion来做。用i, j 两个指针,从左边扫到右边,两个一起走。s.charAt(i) != t.charAt(j原创 2014-12-10 15:03:02 · 2423 阅读 · 0 评论 -
Longest Substring with At Least K Repeating Characters
Find the length of the longest substringTof a given string (consists of lowercase letters only) such that every character inTappears no less thanktimes.Example 1:Input:s = "aaabb", k =原创 2016-09-11 08:19:28 · 2005 阅读 · 0 评论 -
Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".思路:首先将原来string split成 string array,然后倒着再连接起来。注意: 用stringbuilder,avoid c...原创 2014-11-23 07:47:25 · 526 阅读 · 0 评论 -
Reverse String
Write a function that takes a string as input and returns the string reversed.Example 1:Input: "hello"Output: "olleh"Example 2:Input: "A man, a plan, a canal: Panama"Output: "amanaP :lana...原创 2018-12-25 13:20:06 · 119 阅读 · 0 评论 -
Encode and Decode Strings
Design an algorithm to encodea list of stringstoa string. The encoded string is then sent over the network and is decoded back to the original list of strings.Machine 1 (sender) has the functio原创 2016-09-01 08:30:39 · 464 阅读 · 0 评论 -
Substring with Concatenation of All Words
You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without原创 2014-12-19 05:57:19 · 428 阅读 · 0 评论 -
Shortest Palindrome
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.For exampl原创 2016-09-06 08:14:50 · 390 阅读 · 0 评论 -
Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is9534330.Note: The result may be very原创 2015-01-15 16:10:25 · 481 阅读 · 0 评论 -
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原创 2016-07-09 05:10:51 · 222 阅读 · 0 评论 -
Flip Game
You are playing the following Flip Game with your friend: Given a string that contains only these two characters: + and -, you and your friend take turns to flip two consecutive "++" into "--". Th原创 2016-07-06 14:52:08 · 260 阅读 · 0 评论 -
Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may assume t...原创 2016-06-29 13:54:32 · 240 阅读 · 0 评论 -
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 case原创 2014-01-20 13:30:16 · 554 阅读 · 0 评论 -
Reverse Words in a String II
Given an input string, reverse the string word by word. A word is defined as a sequence of non-space characters.The input string does not contain leading or trailing spaces and the words are alway原创 2016-10-18 01:23:50 · 301 阅读 · 0 评论 -
Palindrome Permutation
Given a string, determine if a permutation of the string could form a palindrome.For example,"code"-> False,"aab"-> True,"carerac"-> True.public class Solution { public boolean ca原创 2016-07-05 05:34:58 · 290 阅读 · 0 评论 -
Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.Show TagsHave you m原创 2014-12-20 12:26:24 · 417 阅读 · 0 评论 -
Sentence Screen Fitting
Given a rows x cols screen and a sentence represented by a list of words, find how many times the given sentence can be fitted on the screen.Note:A word cannot be split into two lines.The or原创 2016-11-13 08:45:26 · 1234 阅读 · 0 评论 -
Count Palindrome in String
string 有多少palindrome substring。exp: 'aba' 返回4 , 'abba' 返回6public class CountPalindrome { public int countPalindrome(String str){ if(str == null || str.length() == 0) return 0; int count =原创 2016-11-01 11:34:38 · 356 阅读 · 0 评论 -
Text Justification
Given an array of words and a lengthL, format the text such that each line has exactlyLcharacters and is fully (left and right) justified.You should pack your words in a greedy approach; that is,原创 2014-12-19 13:25:47 · 518 阅读 · 0 评论 -
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.原创 2014-03-02 13:45:34 · 704 阅读 · 0 评论 -
Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Write原创 2015-02-07 10:28:29 · 989 阅读 · 0 评论