
Leetcode题解java版
文章平均质量分 67
Leetcode是找工作必刷的网站,里面有免费题目约二百七十几道,本专栏将给出每道题的思路和解法,解法用java语言描述。
wuezs
阿里巴巴 高级开发工程师
展开
-
【hihocoder】#1082 : 然而沼跃鱼早就看穿了一切
题目链接:http://hihocoder.com/problemset/problem/1082?sid=791045题目: fjxmlhx每天都在被沼跃鱼刷屏,因此他急切的找到了你希望你写一个程序屏蔽所有句子中的沼跃鱼(“marshtomp”,不区分大小写)。为了使句子不缺少成分,统一换成 “fjxmlhx” 。输入 输入包括多行。 每行是一个字符串,长度不超过200。 一行的末尾与下一原创 2016-05-08 13:07:41 · 2040 阅读 · 0 评论 -
【hihocoder】#1094 : Lost in the City
题目链接:http://hihocoder.com/problemset/problem/1094题目: 描述 Little Hi gets lost in the city. He does not know where he is. He does not know which direction is north.Fortunately, Little Hi has a map of th原创 2016-10-04 15:12:00 · 1481 阅读 · 0 评论 -
【hihocoder】#1051 : 补提交卡
题目链接:http://hihocoder.com/problemset/problem/1051题目: 描述 小Ho给自己定了一个宏伟的目标:连续100天每天坚持在hihoCoder上提交一个程序。100天过去了,小Ho查看自己的提交记录发现有N天因为贪玩忘记提交了。于是小Ho软磨硬泡、强忍着小Hi鄙视的眼神从小Hi那里要来M张”补提交卡”。每张”补提交卡”都可以补回一天的提交,将原本没有提交原创 2016-10-04 15:16:35 · 1404 阅读 · 0 评论 -
【Leetcode】Convert a Number to Hexadecima
题目链接:https://leetcode.com/problems/convert-a-number-to-hexadecimal/题目:Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used原创 2016-10-03 14:21:59 · 1466 阅读 · 2 评论 -
【Leetcode】409. Longest Palindrome
题目链接:https://leetcode.com/contest/7/problems/longest-palindrome/题目: Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with t原创 2016-10-02 13:04:32 · 1978 阅读 · 0 评论 -
【Leetcode】408. Valid Word Abbreviation
题目链接:https://leetcode.com/contest/7/problems/valid-word-abbreviation/题目: Given a non-empty string s and an abbreviation abbr, return whether the string matches with the given abbreviation.A string suc原创 2016-10-02 13:09:02 · 3085 阅读 · 0 评论 -
【Leetcode】410. Split Array Largest Sum
题目链接:https://leetcode.com/contest/7/problems/split-array-largest-sum/]题目:Given an array which consists of non-negative integers and an integer m, you can split the array into m non-empty con原创 2016-10-02 13:19:52 · 4852 阅读 · 0 评论 -
【Leetcode】401. Binary Watch
题目链接:https://leetcode.com/contest/5/problems/binary-watch/题目: A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).Each LED原创 2016-09-18 13:48:33 · 3152 阅读 · 0 评论 -
【Leetcode】400. Nth Digit
题目链接:https://leetcode.com/contest/5/problems/nth-digit/题目: Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, … Note: n is positive and will fit within the range原创 2016-09-18 13:58:43 · 6382 阅读 · 0 评论 -
【Leetcode】402. Remove K Digits
题目链接:https://leetcode.com/contest/5/problems/remove-k-digits/题目: Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possib原创 2016-09-18 14:24:53 · 3383 阅读 · 0 评论 -
【Hihocoder】#1049 : 后序遍历
题目链接:http://hihocoder.com/problemset/problem/1049题目描述:没错!小Ho在这一周遇到的问题便是:给出一棵二叉树的前序和中序遍历的结果,还原这棵二叉树并输出其后序遍历的结果。输入每个测试点(输入文件)有且仅有一组测试数据。每组测试数据的第一行为一个由大写英文字母组成的字符串,表示该二叉树的前序遍历原创 2016-09-17 12:56:27 · 1204 阅读 · 0 评论 -
【hihocoder】#1039 : 字符消除
题目:小Hi最近在玩一个字符消除游戏。给定一个只包含大写字母"ABC"的字符串s,消除过程是如下进行的:1)如果s包含长度超过1的由相同字母组成的子串,那么这些子串会被同时消除,余下的子串拼成新的字符串。例如"ABCCBCCCAA"中"CC","CCC"和"AA"会被同时消除,余下"AB"和"B"拼成新的字符串"ABB"。2)上述消除会反复一轮一轮进行,直到新的字符串不包含原创 2016-09-16 19:06:14 · 1124 阅读 · 0 评论 -
【hihocoder】1014 : Trie树
题目懒得贴了。。http://hihocoder.com/problemset/problem/1014思路:easy。。trie树。。。。不同点在于。。为了查询前缀效率更高,在该树中添加节点时,在添加过程中的节点都记录一下以该节点为父节点有多少个子节点。。。。。(说的我头都晕了,其实就是add word时,从root到新节点经过的路径上的每个节点记录值都加一)原创 2016-09-16 19:19:55 · 884 阅读 · 0 评论 -
【hihocoder】#1366 : 逆序单词
题目链接:http://hihocoder.com/problemset/problem/1366思路:easy ,不解释算法:import java.util.HashSet;import java.util.Scanner;import java.util.Set;/** * http://hihocoder.com/problemset/problem原创 2016-09-16 19:21:52 · 1201 阅读 · 0 评论 -
【hihocoder】1141 : 二分·归并排序之逆序对
题目链接:http://hihocoder.com/problemset/problem/1141题目:我们可以看到,船默认排序是以等级为参数。但实际上一个船的火力值和等级的关系并不大,所以会存在A船比B船等级高,但是A船火力却低于B船这样的情况。比如上图中77级的飞龙改二火力就小于55级的夕立改二。现在Nettle将按照等级高低的顺序给出所有船的火力值,请你计算出一共有多少对船满原创 2016-09-16 19:37:45 · 1348 阅读 · 0 评论 -
【Leetcode】386. Lexicographical Numbers
题目链接:https://leetcode.com/problems/lexicographical-numbers/ 题目: Given an integer n, return 1 - n in lexicographical order.For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9].Please optimiz原创 2016-09-15 16:29:48 · 1966 阅读 · 0 评论 -
【Leetcode】Shortest Palindrome
题目链接:https://leetcode.com/problems/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 palindrom原创 2016-09-13 15:02:01 · 858 阅读 · 0 评论 -
【Leetcode】399. Evaluate Division
题目链接:https://leetcode.com/contest/4/problems/evaluate-division/题目:Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (flo原创 2016-09-11 21:12:15 · 5387 阅读 · 0 评论 -
【Leetcode】396. Rotate Function
题目链接:题目:Given an array of integers A and let n to be its length.Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a "rotation function" F on A as原创 2016-09-11 21:15:46 · 3077 阅读 · 0 评论 -
【Leetcode】397. Integer Replacement
题目链接:https://leetcode.com/contest/4/problems/integer-replacement/题目:Given a positive integer n and you can do operations as follow:If n is even, replace n with n/2.If n is odd, you can原创 2016-09-11 21:19:35 · 3961 阅读 · 0 评论 -
【Leetcode】398. Random Pick Index
题目链接:https://leetcode.com/contest/4/problems/random-pick-index/题目:Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that t原创 2016-09-11 21:22:49 · 3729 阅读 · 1 评论 -
【Leetcode】Range Sum Query - Mutable
题目链接:https://leetcode.com/problems/range-sum-query-mutable/题目:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.The update(i, val) functi原创 2016-09-08 11:09:35 · 718 阅读 · 0 评论 -
【Leetcode】UTF-8 Validation
题目链接:https://leetcode.com/problems/utf-8-validation/题目:A character in UTF8 can be from 1 to 4 bytes long, subjected to the following rules:For 1-byte character, the first bit is a 0, follo原创 2016-09-07 19:41:10 · 2073 阅读 · 0 评论 -
【Leetcode】395. Longest Substring with At Least K Repeating Characters
题目链接:https://leetcode.com/problems/longest-substring-with-at-least-k-repeating-characters/题目:Find the length of the longest substring T of a given string (consists of lowercase letters only) s原创 2016-09-06 21:22:22 · 1868 阅读 · 0 评论 -
【Leetcode】394. Decode String
题目链接:https://leetcode.com/contest/3/problems/decode-string/题目:Given an encoded string, return it's decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the s原创 2016-09-04 22:37:25 · 1761 阅读 · 0 评论 -
【Leetcode】Is Subsequence
题目链接:https://leetcode.com/contest/3/problems/is-subsequence/题目:Given a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters原创 2016-09-04 22:40:01 · 1892 阅读 · 1 评论 -
【Leetcode】Two Sum II - Input array is sorted
题目链接:https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/题目:Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specifi原创 2016-09-01 09:37:55 · 1345 阅读 · 4 评论 -
【Leetcode】Longest Absolute File Path
题目链接:https://leetcode.com/problems/longest-absolute-file-path/题目:Suppose we abstract our file system by a string in the following manner:The string "dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext原创 2016-08-30 14:47:26 · 2884 阅读 · 0 评论 -
【Leetcode】Mini Parser
题目链接:https://leetcode.com/problems/mini-parser/题目:Given a nested list of integers represented as a string, implement a parser to deserialize it.Each element is either an integer, or a list -原创 2016-08-15 09:52:03 · 3550 阅读 · 0 评论 -
【Leetcode】Shuffle an Array
题目链接:https://leetcode.com/problems/shuffle-an-array/题目:Shuffle a set of numbers without duplicates.Example:// Init an array with set 1, 2, and 3.int[] nums = {1,2,3};Solution solution原创 2016-08-12 21:39:35 · 3235 阅读 · 0 评论 -
【Leetcode】Ransom Note
题目链接:https://leetcode.com/problems/ransom-note/题目:Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that wi原创 2016-08-12 07:31:31 · 3017 阅读 · 0 评论 -
【Leetcode】Linked List Random Node
题目链接:https://leetcode.com/problems/linked-list-random-node/题目:Given a singly linked list, return a random node's value from the linked list. Each node must have the same probability of being c原创 2016-08-10 11:09:03 · 2344 阅读 · 0 评论 -
【Leetcode】Insert Delete GetRandom O(1) - Duplicates allowed
题目链接:https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed/题目:Design a data structure that supports all following operations in average O(1) time.Note: Duplicate elemen原创 2016-08-09 22:19:11 · 2686 阅读 · 3 评论 -
【Leetcode】Insert Delete GetRandom O(1)
题目链接:https://leetcode.com/problems/insert-delete-getrandom-o1/题目:Design a data structure that supports all following operations in average O(1) time.insert(val): Inserts an item val to原创 2016-08-07 09:14:08 · 4493 阅读 · 0 评论 -
【Leetcode】Kth Smallest Element in a Sorted Matrix
题目链接:https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/题目:Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest eleme原创 2016-08-01 21:54:16 · 4126 阅读 · 0 评论 -
Leetcode题目更新提醒小脚本~
Leetcode缺少一个 出现新题目就发邮件提醒用户的功能,所以写了一个脚本。脚本有两个函数:检查leet网站是否有新题目,并且题目是能做的、没加锁的;发邮件提醒用户。网站解析用的是beautifulSoup 所以需要预先安装bs4模块脚本写完需要上传到云主机上,这里简单起见 我用的是实验室的服务器,上传并运行该脚本。这里有个小问题要解决,ssh运行python断开终端后会杀死该进原创 2016-07-26 21:04:05 · 912 阅读 · 1 评论 -
【Leetcode】Combination Sum IV
题目链接:https://leetcode.com/problems/combination-sum-iv/题目:Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a pos原创 2016-07-25 22:43:10 · 4671 阅读 · 0 评论 -
【Leetcode】Guess Number Higher or Lower II
题目链接:题目: We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I’ll tell you whether the number I picke原创 2016-07-24 00:00:23 · 4326 阅读 · 0 评论 -
【Leetcode】Wiggle Subsequence
题目链接:https://leetcode.com/problems/wiggle-subsequence/题目: A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negati原创 2016-07-22 23:19:16 · 2942 阅读 · 0 评论 -
【Leetcode】Wildcard Matching
题目链接:https://leetcode.com/problems/wildcard-matching/题目:Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of charact原创 2016-07-14 16:35:13 · 1085 阅读 · 0 评论