leetcode刷题
KarryChang.
三年的局点
展开
-
Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Note:The input is assumed to be a 32-bit signed integer. Your function s原创 2017-02-13 15:45:35 · 364 阅读 · 0 评论 -
Rotate Array
题目:Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:Try to come up as many solution原创 2017-03-19 20:31:36 · 313 阅读 · 0 评论 -
Maximum Gap
Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements原创 2017-03-19 21:03:56 · 319 阅读 · 0 评论 -
Sort Characters By Frequency
Given a string, sort it in decreasing order based on the frequency of characters.Example 1:Input:"tree"Output:"eert"Explanation:'e' appears twice while 'r' and 't' both appear once.So 'e原创 2017-03-20 13:37:41 · 255 阅读 · 0 评论 -
Number of Boomerangs
题目:Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such that the distance between iand j equals the distance between i and k (the o原创 2017-03-20 13:46:15 · 268 阅读 · 0 评论 -
Largest Number
题目:Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result原创 2017-03-20 15:56:51 · 274 阅读 · 2 评论 -
Find Minimum in Rotated Sorted Array
题目:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.You may ass原创 2017-03-20 16:31:48 · 238 阅读 · 0 评论 -
Move Zeroes
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling you原创 2017-03-20 19:26:45 · 254 阅读 · 2 评论 -
Longest Increasing Subsequence
题目:Given an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3, 7, 101原创 2017-03-20 20:30:47 · 264 阅读 · 0 评论 -
Word Search
题目:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or v原创 2017-03-20 21:11:13 · 277 阅读 · 0 评论 -
Java统计单词频率
利用集合类,其中按照map中value排列需要考虑一下具体思路,最后结合list完成排列/** * Created by changqing on 2017/3/4. */import java.io.*;import java.util.*;public class test { public static void main(String [] args) throw原创 2017-03-05 12:17:11 · 3015 阅读 · 0 评论 -
Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next()原创 2017-03-19 20:24:52 · 309 阅读 · 0 评论 -
subTree
题目: 输入两棵树A,B,判断B是否是A数的子树tips:先遍历找出A和B的root节点val值相同的节点,然后由此出发,判断之后的左右子树是否相同。递归算法:代码class TreeNode{ int val=0; TreeNode left=null; TreeNode right=null; public TreeNode(int val){原创 2017-03-19 19:58:48 · 428 阅读 · 0 评论 -
Add Two Numbers
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 numbers and return i原创 2017-02-13 15:53:55 · 469 阅读 · 0 评论 -
permutation
题目大意:给你一组数据(Integer),里面可能有重复数据,让你进行全排列。即有重复元素的全排列问题,我之前博客在算法分析与设计里面写过类似的方法。思路:回溯法思想package Permutations;import java.util.ArrayList;import java.util.Arrays;public class permutations {原创 2017-02-13 15:59:50 · 455 阅读 · 0 评论 -
Word Search II 解题报告
转载自:http://blog.csdn.net/ljiabin/article/details/45846527 【题目】Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from lett转载 2017-02-25 11:44:02 · 596 阅读 · 0 评论 -
Find Largest Value in Each Tree Row
题目:You need to find the largest value in each row of a binary tree.Example:Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3, 9]tips:主要考察原创 2017-03-19 18:18:30 · 635 阅读 · 0 评论 -
Find Bottom Left Tree Value
题目:Given a binary tree, find the leftmost value in the last row of the tree.Example 1:Input: 2 / \ 1 3Output:1Example 2: Input: 1 / \ 2原创 2017-03-19 18:24:24 · 588 阅读 · 0 评论 -
K-diff Pairs in an Array
题目:Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), where i and j are both原创 2017-03-19 18:29:16 · 299 阅读 · 0 评论 -
Minimum Absolute Difference in BST
题目:Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.Example:Input: 1 \ 3 / 2Output:1Expl原创 2017-03-19 18:34:09 · 463 阅读 · 0 评论 -
Smallest Good Base
题目:For an integer n, we call k>=2 a good base of n, if all digits of n base k are 1.Now given a string representing n, you should return the smallest good base of n in string format. E原创 2017-03-19 18:40:53 · 364 阅读 · 0 评论 -
4Sum II
题目: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 ha原创 2017-03-19 18:44:44 · 351 阅读 · 0 评论 -
Heater
Winter is coming! Your first job during the contest is to design a standard heater with fixed warm radius to warm all the houses.Now, you are given positions of houses and heaters on a horizontal原创 2017-03-19 18:51:26 · 408 阅读 · 0 评论 -
Equal Tree Partition
public boolean canPartition(int[] nums) { int sum = 0; for (int num : nums) { sum += num; } if ((sum & 1) == 1) { return false; } sum /= 2; int n原创 2017-08-25 21:36:03 · 542 阅读 · 0 评论