
算法与数据结构
kevin聪
Success is not final.Failure is not fatal.It is the courage to continue that counts.
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
HashTable-202-Happy Number
Description: Write an algorithm to determine if a number is “happy”.A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of...原创 2018-01-22 19:00:13 · 259 阅读 · 0 评论 -
HashTable-594-Longest Harmonious Subsequence
Description: We define a harmonious array is an array where the difference between its maximum value and its minimum value is exactly 1.Now, given an integer array, you need to find the length of i...原创 2018-01-22 19:17:29 · 246 阅读 · 0 评论 -
HashTable-645-Set Mismatch
Description:The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of the numbers in the set got duplicated to another number in the set, which results in r...原创 2018-01-22 19:31:32 · 252 阅读 · 0 评论 -
HashTable-1-Two Sum
Description: Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not...原创 2018-01-22 19:42:45 · 289 阅读 · 0 评论 -
HashTable-205-Isomorphic Strings
Description: Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced...原创 2018-01-22 19:53:08 · 221 阅读 · 0 评论 -
HashTable-438-Find All Anagrams in a String
Description: Given a string s and a non-empty string p, find all the start indices of p’s anagrams in s.Strings consists of lowercase English letters only and the length of both strings s and p wil...原创 2018-01-22 20:31:08 · 221 阅读 · 0 评论 -
HashTable-290-Word Pattern
Description: Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word i...原创 2018-01-22 20:36:30 · 169 阅读 · 0 评论 -
HashTable-204-Count Primes
Description: Count the number of prime numbers less than a non-negative number, n.Solution:class Solution { public int countPrimes(int n) { boolean[]isPrime = new boolean[n]; ...原创 2018-01-22 20:56:51 · 305 阅读 · 0 评论 -
HashTable-535-Encode and Decode TinyURL
Description: TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such as http://tinyurl.com/4e9iAk.Design the e...原创 2018-01-22 21:01:21 · 222 阅读 · 0 评论 -
HashTable-219-Contains Duplicate II
Description: Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j ...原创 2018-01-22 20:43:08 · 240 阅读 · 0 评论 -
Math-368-Largest Divisible Subset
Description: Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj = 0 or Sj % Si = 0.If there are multiple...原创 2018-01-30 19:10:24 · 313 阅读 · 0 评论 -
Math-396-Rotate Function
Description: 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 fol...原创 2018-01-30 19:24:24 · 305 阅读 · 0 评论 -
Math-223-Rectangle Area
Description: Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that ...原创 2018-01-30 19:31:11 · 310 阅读 · 0 评论 -
Math-264-Ugly Number II
Description: Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of...原创 2018-01-30 19:41:19 · 249 阅读 · 0 评论 -
Math-397-Integer Replacement
Description: 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 replace n with either n + 1 or n - 1.What is the minimum numbe...原创 2018-01-30 19:57:51 · 380 阅读 · 0 评论 -
Math-60-Permutation Sequence
Description: The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3): "123" ...原创 2018-01-30 20:23:46 · 246 阅读 · 0 评论 -
Math-2-Add Two Numbers
Description: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two number...原创 2018-01-30 20:31:02 · 243 阅读 · 0 评论 -
Math-365-Water and Jug Problem
Description: You are given two jugs with capacities x and y litres. There is an infinite amount of water supply available. You need to determine whether it is possible to measure exactly z litres usi...原创 2018-01-30 20:55:23 · 324 阅读 · 0 评论 -
Math-43-Multiply Strings
Description: Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2.Note:The length of both num1 and num2 is < 110.Both num1 and num2 contai...原创 2018-01-30 21:06:00 · 212 阅读 · 0 评论 -
HashTable-676-Implement Magic Dictionary
Description: Implement a magic directory with buildDict, and search methods.For the method buildDict, you’ll be given a list of non-repetitive words to build a dictionary.For the method search, ...原创 2018-01-23 19:20:55 · 257 阅读 · 0 评论 -
HashTable-347-Top K Frequent Elements
Description:Given a non-empty array of integers, return the k most frequent elements.For example, Given [1,1,1,2,2,3] and k = 2, return [1,2]. Note:You may assume k is always valid, 1 ≤ k ≤...原创 2018-01-23 19:31:49 · 234 阅读 · 0 评论 -
HashTable-648-Replace Words
Description: In English, we have a concept called root, which can be followed by some other words to form another longer word - let’s call this word successor. For example, the root an, followed by ...原创 2018-01-23 19:54:03 · 239 阅读 · 0 评论 -
HashTable-94-Binary Tree Inorder Traversal
Description: Given a binary tree, return the inorder traversal of its nodes’ values.For example: Given binary tree [1,null,2,3], 1 \ 2 / 3return [1,3,2]. Note: Recursive so...原创 2018-01-23 19:44:10 · 250 阅读 · 0 评论 -
HashTable-454-4Sum II
Description: Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.To make problem a bit easier, all A, B, C, D h...原创 2018-01-23 20:05:15 · 230 阅读 · 0 评论 -
HashTable-748-Shortest Completing Word
Description: Find the minimum length word from a given dictionary words, which has all the letters from the string licensePlate. Such a word is said to complete the given string licensePlateHere, f...原创 2018-01-23 16:36:43 · 278 阅读 · 0 评论 -
HashTable-739-Daily Temperatures
Description: Given a list of daily temperatures, produce a list that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day f...原创 2018-01-23 16:52:03 · 246 阅读 · 0 评论 -
HashTable-609-Find Duplicate File in System
Description: Given a list of directory info including directory path, and all the files with contents in this directory, you need to find out all the groups of duplicate files in the file system in t...原创 2018-01-23 17:31:05 · 350 阅读 · 0 评论 -
HashTable-508-Most Frequent Subtree Sum
Description: Given the root of a tree, you are asked to find the most frequent subtree sum. The subtree sum of a node is defined as the sum of all the node values formed by the subtree rooted at that...原创 2018-01-23 17:43:59 · 240 阅读 · 0 评论 -
HashTable-451-Sort Characters By Frequency
Description: Given a string, sort it in decreasing order based on the frequency of characters.Solution://维护一个bucket,存储频率对应的元素,逆序遍历bucket(即频率由大到小排列),将字符填充入sb中返回public class Solution { publi...原创 2018-01-23 17:57:11 · 133 阅读 · 0 评论 -
HashTable-554-Brick Wall
Description: There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. You want to draw a vertical line from ...原创 2018-01-24 15:55:16 · 226 阅读 · 0 评论 -
HashTable-692-Top K Frequent Words
Description: Given a non-empty list of words, return the k most frequent elements.Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, then the wo...原创 2018-01-24 16:02:57 · 314 阅读 · 0 评论 -
HashTabel-525-Contiguous Array
Description: Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1.Example 1:Input: [0,1]Output: 2Explanation: [0, 1] is the longest contiguous s...原创 2018-01-24 16:20:41 · 264 阅读 · 0 评论 -
HashTable-718-Maximum Length of Repeated Subarray
Description: Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays.Example 1:Input:A: [1,2,3,2,1]B: [3,2,1,4,7]Output: 3Explanation: The re...原创 2018-01-24 18:09:09 · 225 阅读 · 0 评论 -
Math-50-Pow(x, n)
Description: Implement pow(x, n). Example 1: Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100Best Solution://举例来说,2^7 = 2 * 2^2 * 2^4,2^8 = (((2 * 2)...原创 2018-01-31 20:45:15 · 345 阅读 · 0 评论 -
Math-754. Reach a Number
Description: You are standing at position 0 on an infinite number line. There is a goal at position target.On each move, you can either go left or right. During the n-th move (starting from 1), yo...原创 2018-01-31 21:05:45 · 381 阅读 · 0 评论 -
Math-523-Continuous Subarray Sum
Description: Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to the multiple of k, that i...原创 2018-01-31 21:38:51 · 333 阅读 · 0 评论 -
Math-29-Divide Two Integers
Description: Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT. Solution:举例来说,63 = 2^5 + 2^4 + 2^3 + 2^2 + 2^1 + 2^0,也就是16 + 8 + 4...原创 2018-01-31 22:09:20 · 289 阅读 · 0 评论 -
Math-8-String to Integer (atoi)
Description: 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 possi...原创 2018-01-31 22:19:01 · 235 阅读 · 0 评论 -
LinkedList-237-Delete Node in a Linked List
Description: Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the...原创 2018-01-31 22:27:42 · 308 阅读 · 0 评论 -
LinkedList-206-Reverse Linked List
Description: Reverse a singly linked list.Iterative Version:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { v...原创 2018-01-31 22:35:57 · 289 阅读 · 0 评论