自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(61)
  • 收藏
  • 关注

原创 134. Gas Station

There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its ne...

2018-04-08 23:47:44 179

原创 453. Minimum Moves to Equal Array Elements

Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1.Example:Input:[1,2,3]Output:...

2018-03-06 13:11:25 201

原创 96. Unique Binary Search Trees

Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ / ...

2018-02-25 20:42:27 190

原创 627. Swap Salary

Given a table salary, such as the one below, that has m=male and f=female values. Swap all f and m values (i.e., change all f values to m and vice versa) with a single update query and no intermediate

2018-01-21 14:16:43 182

原创 438. Find All Anagrams in a String

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 stringss and p will not be

2018-01-10 01:18:25 233

原创 287. Find the Duplicate Number

There must be:2s = s + n*c=> s = n*c…(1)Then, assume the length from start point to entry point is x, and the length from the entrypoint to the meet point is a.There must be: s = x+a…(2)So

2018-01-09 02:02:53 169

原创 594. Longest Harmonious Subsequence

We define a harmonious array is an array where the difference between its maximum value and its minimum value isexactly 1.Now, given an integer array, you need to find the length of its longest ha

2018-01-04 22:25:07 170

原创 222. Count Complete Tree Nodes

Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled,

2018-01-04 15:56:12 154

原创 383. Ransom Note

Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; ot

2018-01-03 17:09:09 174

原创 200. Number of Islands

Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume

2018-01-02 19:16:54 162

原创 401. 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 theminutes (0-59).Each LED represents a zero or one, with the least significant bit on

2017-12-29 19:25:01 163

原创 441. Arranging Coins

You have a total of n coins that you want to form in a staircase shape, where everyk-th row must have exactly k coins.Given n, find the total number of full staircase rows that can be formed.n i

2017-11-09 23:34:39 174

原创 129. Sum Root to Leaf Numbers

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number123.Find the total sum

2017-11-09 00:33:01 151

原创 507. Perfect Number

We define the Perfect Number is a positive integer that is equal to the sum of all itspositive divisors except itself. Now, given an integer n, write a function that returns true when it is a perf

2017-11-08 01:52:46 191

原创 563. Binary Tree Tilt

Given a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all right subtree

2017-11-07 00:34:49 184

原创 405. 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.Note:All letters in hexadecimal (a-f) must be in lowercase.The hexadec

2017-11-06 00:31:04 165

原创 98. Validate Binary Search Tree

Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.The

2017-11-03 01:15:28 160

原创 60. Permutation Sequence

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""132""213""231""312""

2017-11-02 01:30:14 187

原创 225. Implement Stack using Queues

Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whet

2017-11-01 23:26:07 460

原创 89. Gray Code

The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of gr

2017-10-31 00:58:40 166

原创 258. Add Digits

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one

2017-10-29 14:10:53 213

原创 371. Sum of Two Integers

Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.源码:class Solution {    public int getSum(int a, i

2017-10-28 23:46:40 138

原创 162. Find Peak Element

A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, in that

2017-10-28 00:39:41 149

原创 190. Reverse Bits

Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as0011100101

2017-10-27 01:28:10 113

原创 367. Valid Perfect Square

Given a positive integer num, write a function which returns True if num is a perfect square else False.Note: Do not use any built-in library function such as sqrt.Example 1:Input: 16Return

2017-10-25 11:31:12 221

原创 303. Range Sum Query - Immutable

Given an integer array nums, find the sum of the elements between indicesi and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRang

2017-10-24 13:03:30 198

原创 75. Sort Colors

Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers 0,

2017-10-24 00:33:22 159

原创 204. Count Primes

Description:Count the number of prime numbers less than a non-negative number, n.官方代码:public class Solution { public int countPrimes(int n) { boolean[] notPrime = new boolean[n

2017-10-20 15:08:10 144

原创 196. Delete Duplicate Emails

Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id.+----+------------------+| Id | Email |+----+---

2017-10-20 14:45:58 171

原创 205. Isomorphic Strings

Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to gett.All occurrences of a character must be replaced with another

2017-10-20 14:38:35 120

原创 197. Rising Temperature

Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to its previous (yesterday's) dates.+---------+------------+------------------+| Id(INT) | Date(DATE

2017-10-20 02:02:58 132

原创 198. House Robber

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house

2017-10-20 02:00:10 139

原创 268. Missing Number

Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm should run

2017-10-18 22:44:18 148

原创 62. Unique Paths

A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bo

2017-10-17 20:48:21 158

原创 110. Balanced Binary Tree

Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees ofevery node never differ

2017-10-15 16:27:43 204

原创 108. Convert Sorted Array to Binary Search Tree

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.源码:/** * Definition for a binary tree node. * public class TreeNode { *     int val; *    

2017-10-15 15:48:03 170

原创 160. Intersection of Two Linked Lists

Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists: A: a1 → a2 ↘

2017-10-15 10:50:10 232

原创 39. Combination Sum

Given a set of candidate numbers (C)(without duplicates) and a target number (T), find all unique combinations inC where the candidate numbers sums to T.The same repeated number may be chosen

2017-10-14 20:20:06 337

原创 122. Best Time to Buy and Sell Stock II

Say you have an array for which the ith element is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one

2017-10-13 23:44:43 174

原创 231. Power of Two

Given an integer, write a function to determine if it is a power of two.较好的思路:讲这个数与其前一个数作与运算,一旦为0满足要求,否则不满足要求官方解答:Power of 2 means only one bit of n is '1', so use the trick n&(n-1)==0 to

2017-10-13 22:51:13 759

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除