`
文章列表
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 is, pack as many words as you can in each line. Pad extra spaces ' ' when necessary so that each line ha ...
Validate if a given string is numeric. Some examples: "0" => true " 0.1 " => true "abc" => false "1 a" => false "2e10" => true Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front ...
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 without any intervening characters. For example, given: s: "barfoothefoobarman" words: [&quo ...
Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", => "/home" path = "/a/./b/../../c/", => "/c" [分析] 思路很简单,遇到“.”跳过,遇到“..”删除其前面一级目录,使用堆栈来删除前一级目录的想法很妙(要是我自己想出来就好了~)。 另外分割字符串来处理的思路也要用心体会,联系reverse-words-in-a-string 一 ...
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   N A P L S I I G Y   I   R And then read line by line: "PAHNAPLSIIGYIR" Write the code that will ...
线上升级JDK8后发现jps, jstat命令对于一个进程A有效,而另一个进程B则无效,运行jps会报错process information unavailable, 运行jstat 报错那个pid not found。 最后发现两个进程启动用户不同,jps、jstat无效的进程B是odin用户启动,需要以如下方式执行: sudo -u odin jps pid 命令有效的前提是执行用户拥有这个命令的sudo odin权限。     
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 上的每一位同num1 相乘,由于运算顺序从高到低,每次运算时将上一次运算结果后加0,(相当于*10)后同本次乘积结果加和。 高效做法(Method 2)思路:num1 * num2, num2上的每一位依次和 ...
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 there is no such window in S that covers all characters in T, retu ...
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 "bbbbb" the longest substring is "b", with the length of 1. [ ...
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上分析指出面试时写出暴力法即可,关键是暴力法代码要写得clean。 实现1采用two pointer 方式,代码上不如实现1.1 clean。两者算法复杂度均为O(n * m)。 实现2 是一种个人认为最容易理解的O(n) ...

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 == null) return null; if (a == null || a.length() == 0) return ...
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 contain only digits and the . character. The . character does not represent a decimal point and is ...
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 example: Given "aacecaaa", return "aaacecaaa". Given "abcd", return "dcba ...
<div class="iteye-blog-content-contain" style="font-size: 14px"></div> 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从小到大逐 ...
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers. Ensure that numbers within the set are sorted in ascending order. Example 1:Input: k = 3, n = 7 Output: [[1,2,4]] Examp ...
Global site tag (gtag.js) - Google Analytics