
String
iteye_17352
这个作者很懒,什么都没留下…
展开
-
Leetcode - Longest Palindrome Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.[balabala] Method1从小到大...原创 2015-06-11 09:48:56 · 105 阅读 · 0 评论 -
Leetcode - 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 am原创 2015-06-21 10:42:28 · 80 阅读 · 0 评论 -
Leetcode - Text Justification
Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy approach; that i...原创 2015-06-22 18:29:38 · 94 阅读 · 0 评论 -
Leetcode - Strobogrammatic Number
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).Write a function to determine if a number is strobogrammatic. The number is represented as...原创 2015-08-22 10:48:09 · 126 阅读 · 0 评论 -
Leetcode - Group Shifted String
Given a string, we can "shift" each of its letter to its successive letter, for example: "abc" -> "bcd". We can keep "shifting" which forms the sequence:"abc" -> "bcd" -> ... -> &q原创 2015-08-22 16:20:31 · 129 阅读 · 0 评论 -
Leetcode - Isomorphic Strings
[分析]思路1:维护两个哈希表,char[] map, boolean[] used, 长度均为256,map[charS] = charT, 表示将字符charS 映射为charT, used[charT]==true 表示charT已经被某个字符映射过了。同步遍历字符串s & t,记两者当前的字符分别为charS, charT, 若charS是新字符,且charT没有被使用,则我们可将其同...原创 2015-08-23 09:51:03 · 78 阅读 · 0 评论 -
Leetcode - One Edit Distance
[分析]两字符串相同或者长度差异大于等于2都不符合要求,只需要检查那些长度相同或者相差为1的情况。逐个字符检查,发现第一个差异字符,若s和t长度相等将s中字符替换为t中字符,若不等则在s中插入t当前字符,然后跳出检查循环。若检查过程无差异字符(说明长度差1)或者消除发现的第一个差异后两字符串相等说明两字符串编辑距离为1.这个思路和实现参考[url]https://leetcode.com/...原创 2015-08-27 20:26:17 · 91 阅读 · 0 评论 -
Leetcode - Read N Characters Given Read4
The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters left in the...原创 2015-08-27 20:56:29 · 123 阅读 · 0 评论 -
Leetcode - Read N Characters Given Read4 II - Call Multiple Times
The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters left in the...原创 2015-08-28 09:00:18 · 106 阅读 · 0 评论 -
Leetcode - Substring with Contentaion of All Words
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and wi...原创 2015-06-18 10:01:33 · 90 阅读 · 0 评论 -
Leetcode - Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"[分析] 思路很简单,遇到“.”跳过,遇到“..”删除其前面一级目录,使用堆栈来删除前一级目录的想法很妙(要是我...原创 2015-06-17 21:58:55 · 89 阅读 · 0 评论 -
Leetcode - Shortest Palindrome
Given a string S, you are allowed to convert it to a palindrome by adding characters [color=red]in front of[/color] it. Find and return the shortest palindrome you can find by performing this transfor...原创 2015-06-13 10:55:43 · 114 阅读 · 0 评论 -
Leetcode - Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and co...原创 2015-06-13 16:36:41 · 86 阅读 · 0 评论 -
Leetcode - Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100". public String addBinary(String a, String b) { if (a == null && b ...原创 2015-06-13 17:34:04 · 67 阅读 · 0 评论 -
Leetcode - Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.[分析] 经典的字符查找问题,有四种经典解法, 暴力法,hash法,Boyer-Moorer算法和KMP算法。leetcode上分析指出...原创 2015-06-13 19:54:26 · 104 阅读 · 0 评论 -
Leetcode - Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For ...原创 2015-06-14 15:34:19 · 93 阅读 · 0 评论 -
Leetcode - Minimum Window String
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"....原创 2015-06-14 19:33:23 · 108 阅读 · 0 评论 -
Leetcode - Multiply String
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.[分析] Naive的做法是模拟笔算乘法操作,从高位到低位的顺序将num2...原创 2015-06-15 09:39:35 · 95 阅读 · 0 评论 -
Leetcode - 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...原创 2015-06-15 21:31:06 · 82 阅读 · 0 评论 -
Leetcode - Integer to English Words
[分析]这题通过率之所以非常低是因为有很多corner case,代码写得不好时就很容易在各种corner case上刷跟头,第二十遍才被Accept,自己还真是有耐心。然后看到讨论区中的解答,一对比,差距啊,努力努力再努力!注意:不需要添加“and”大神漂亮的作品:[url]https://leetcode.com/discuss/55462/my-clean-java-solu...原创 2015-09-04 20:53:16 · 105 阅读 · 0 评论