字符串
文章平均质量分 77
nicaishibiantai
这个作者很懒,什么都没留下…
展开
-
Generate parenthesis
当既可以append "(" 也可以 append ")"时:left == right || left <right,同时generate 这样两个String;不可以的话就append ")": left == 0public class Solution { public ListgenerateParenthesis(int n) { List resul原创 2014-08-11 11:32:10 · 398 阅读 · 0 评论 -
Scramble String
https://oj.leetcode.com/problems/scramble-string/超时的答案:原创 2014-09-17 06:33:45 · 440 阅读 · 0 评论 -
Valid Number
public boolean isNumber(String s) { int start = 0; while (start < s.length() && s.charAt(start) == ' ') { start++; } if (start < s.length() && (s.charAt(sta原创 2014-09-22 06:49:22 · 331 阅读 · 0 评论 -
Decode Ways
A message containing letters from A-Z isbeing encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the totalnumbe原创 2014-08-11 11:31:22 · 320 阅读 · 0 评论 -
Lintcode - Hash fucntion
In data structure Hash, hash function is used to convert a string(or any other type) into an integer smaller than hash size and bigger or equal to zero. The objective of designing a hash function is t原创 2015-01-31 14:42:05 · 3227 阅读 · 0 评论 -
One Edit Distance
Given two strings S and T, determine if they are both one edit distance apart. public boolean isOneEditDistance(String s, String t) { if (Math.abs(s.length() - t.length()) > 1) {原创 2014-12-10 14:11:36 · 965 阅读 · 0 评论 -
Interleaving string
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", ret原创 2014-09-17 12:59:31 · 342 阅读 · 0 评论 -
atoi
public class Solution { public int atoi(Stringstr) { int sign = 1; boolean checkSign = true; boolean checkFirst = true; int result = 0; for (int i原创 2014-08-11 11:32:03 · 299 阅读 · 0 评论 -
Longest Substring with At Most Two Distinct Characters
Given a string, find the length of the longest substring T that contains at most 2 distinct characters.For example, Given s = “eceba”,T is "ece" which its length is 3.和minimum window一样的题。一遍过原创 2015-03-26 11:55:27 · 487 阅读 · 0 评论 -
Wildcard Matching
'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover the entire input string (not partial).The function prototype shoul原创 2015-03-30 08:50:52 · 377 阅读 · 0 评论 -
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. public String multiply(String n原创 2014-09-01 12:52:29 · 548 阅读 · 0 评论 -
两个指针-Substring with Concatenation of All Words
public class Solution { public ArrayListfindSubstring(String S, String[] L) { // Start typing your Java solution below // DO NOT write main() function int wordNum = L.leng原创 2014-08-11 11:30:27 · 312 阅读 · 0 评论 -
Restore IP address
Given a string containing only digits, restore it by returning allpossible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135","255.255.111.35"]. (Order does原创 2014-08-11 11:31:13 · 385 阅读 · 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.Wri原创 2015-04-28 05:24:07 · 396 阅读 · 0 评论 -
Longest palindrome substring
错误:1. 暴力解会超时(即主函数里面两个for 循环,然后判断i,j之间是否为palindrome)2. while loop 总是忘记更改下标,导致死循环。3. 开始的时候没有移动right index,导致奇偶palindrome会错4. maxLen, maxString设置要同步。public class Solution { public Stringlonge原创 2014-08-11 11:31:35 · 351 阅读 · 0 评论 -
Longest substring without repeating characters
Given a string, find the length of the longest substring withoutrepeating characters. For example, the longest substring withoutrepeating letters for "abcabcbb" is "abc", which the length is 3.For原创 2014-08-11 11:32:05 · 298 阅读 · 0 评论 -
Palindrome Partition
Given a string s,partition s suchthat every substring of the partition is a palindrome.Return all possible palindrome partitioningof s.For example, given s = "aab",Return [ ["aa","b"]原创 2014-08-11 11:31:20 · 673 阅读 · 0 评论 -
Word Ladder
Given two words (start and end),and a dictionary, find the length of shortest transformationsequence from start to end,such that:Only one letter can be changedat a timeEach intermediate word mu原创 2014-08-11 11:31:52 · 364 阅读 · 0 评论 -
Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover t原创 2014-09-18 06:30:23 · 385 阅读 · 0 评论 -
Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1",原创 2014-09-19 13:03:14 · 371 阅读 · 0 评论 -
Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/",=> "/home"path = "/a/./b/../../c/",=> "/c"click toshow corner cases.Corner Cases: Did youconsi原创 2014-08-11 11:31:48 · 335 阅读 · 0 评论 -
Reverse words
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".click to show clarification.Clarification:What constitutes原创 2014-09-07 05:59:49 · 369 阅读 · 0 评论 -
Queens
The n-queenspuzzle is the problem of placing n queenson an n�n chessboardsuch that no two queens attack each other.Queens" TITLE="N Queens" />Given an integer n,return all distinct solutions原创 2014-08-11 11:31:16 · 469 阅读 · 0 评论 -
Letter combinations of phone number
http://leetcode.com/oldoj#question_17Given a digit string, return all possible letter combinations thatthe number could represent.A mapping of digit to letters (just like on the telephone button原创 2014-08-11 11:31:07 · 508 阅读 · 0 评论 -
word search
Given a 2D board and a word, find if the word exists in thegrid.The word can be constructed from letters of sequentially adjacentcell, where "adjacent" cells are those horizontally or verticallyn原创 2014-08-11 11:31:11 · 348 阅读 · 0 评论 -
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原创 2014-09-21 05:31:57 · 370 阅读 · 0 评论 -
Word Ladder
public int ladderLength(String start, String end, Set dict) { int level = 1; Set visited = new HashSet(); Queue queue = new LinkedList(); queue.add(start); visi原创 2014-09-22 07:01:47 · 395 阅读 · 0 评论 -
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) { String原创 2014-08-30 13:14:14 · 455 阅读 · 0 评论 -
Regular Expression
public class Solution { public boolean isMatch(String s, String p) { return helper(s, p, 0, 0); } // pos1 s start, pos2 p start boolean helper(String s, String p, int pos1原创 2014-09-18 05:15:43 · 611 阅读 · 0 评论