- 博客(57)
- 收藏
- 关注
原创 247. Strobogrammatic Number II
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).Find all strobogrammatic numbers that are of length = n. For example,Given n = 2, re
2017-03-31 11:24:34 397
原创 397. 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 replace n with either n + 1 or n - 1.What is the minimum number o
2017-03-31 03:06:40 320
原创 423. Reconstruct Original Digits from English
Given a non-empty string containing an out-of-order English representation of digits 0-9, output the digits in ascending order.Note:Input contains only lowercase English letters.Input is g
2017-03-31 02:28:33 212
原创 365. Water and Jug Problem
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 using these two
2017-03-30 08:26:35 623
原创 413. Arithmetic Slices
A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic seque
2017-03-30 06:56:15 231
原创 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-03-30 01:50:33 310
原创 368. Largest Divisible Subset
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 solution
2017-03-29 03:01:26 171
原创 313. Super Ugly Number
Write a program to find the nth super ugly number.Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2, 4, 7, 8, 13,
2017-03-24 11:12:17 215
原创 357. Count Numbers with Unique Digits
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x n.Example:Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x [11,22,33,44,
2017-03-23 07:20:04 280
原创 372. Super Pow
Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.Example1:a = 2b = [3]Result: 8Example
2017-03-23 06:52:14 304
原创 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""3
2017-03-23 02:10:15 207
原创 264. Ugly Number II
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 the first
2017-03-22 08:07:33 236
原创 343. Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, ret
2017-03-21 15:34:17 217
原创 29. Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.1、让divisor一直乘22、如果divisor>dividend,则用dividend - 上一个divisor3、余下的数继续重复1,2步这里有两种情
2017-03-21 10:04:10 280
原创 43. Multiply Strings
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 Both num1 and num2 contains only digits
2017-03-21 07:59:39 203
原创 279. Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n =
2017-03-21 01:44:48 239
原创 516. Longest Palindromic Subsequence
Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000.Example 1:Input: "bbbab"Output: 4One possible longest pali
2017-03-20 14:01:54 443
原创 Installing CUDA 8.0 + cuDNN 5.1 + TensorFlow with Ubuntu 14.04 (下)
Step 2. Install NVIDIA cuDNNOnce the CUDA Toolkit is installed, download cuDNN v5.1 Library(或者从百度云下载) for Linux (note that you will need to register for the Accelerated Computing Developer Program
2017-03-19 10:20:16 2641
原创 Installing CUDA 8.0 + cuDNN 5.1 + TensorFlow with Ubuntu 14.04 (上)
花了一天在Ubuntu 14.04安装CUDA 8.0 + cuDNN 5.1 + TensorFlow,最终成功,记录一下安装过程,方便日后重装。教程大多来自外网,所以就用英文记录,不翻译了。1、Installing CUDA 8.0(1.) Install build essentials.sudo apt-get install build-essential(2.) Go
2017-03-19 09:49:00 2170
原创 319. Bulb Switcher
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off
2017-03-16 14:54:40 470
原创 147. Insertion Sort List
Sort a linked list using insertion sort.linked list 的insertion sort,需要记住第一个node,以后的每一个curnode从第一个往后放到合适的位置。代码如下:/** * Definition for singly-linked list. * public class ListNode { * int va
2017-03-14 15:04:18 227
原创 328. Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in
2017-03-14 02:35:21 175
原创 148. Sort List
Sort a linked list in O(n log n) time using constant space complexity.这里采用merge sort。每次把linked list用slow和fast分成两段,再进行merge。代码如下:/** * Definition for singly-linked list. * public class ListNo
2017-03-13 09:52:08 175
原创 525. Contiguous Array
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 subarray wit
2017-03-12 12:19:35 333
原创 356. Line Reflection
Given n points on a 2D plane, find if there is such a line parallel to y-axis that reflect the given points.Example 1:Given points = [[1,1],[-1,1]], return true.Example 2:Given poi
2017-03-12 09:51:01 285
原创 508. Most Frequent Subtree Sum
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 node (includi
2017-03-11 14:48:47 192
原创 500. Keyboard Row
Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below. Example 1:Input: ["Hello", "Alaska", "D
2017-03-11 10:42:25 216
原创 355. Design Twitter
Design a simplified version of Twitter where users can post tweets, follow/unfollow another user and is able to see the 10 most recent tweets in the user's news feed. Your design should support the fo
2017-03-11 10:07:27 251
原创 314. Binary Tree Vertical Order Traversal
Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bottom, column by column).If two nodes are in the same row and column, the order should be from left
2017-03-10 12:54:10 349
原创 325. Maximum Size Subarray Sum Equals k
Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If there isn't one, return 0 instead.Note:The sum of the entire nums array is guaranteed to fit wi
2017-03-10 09:30:56 304
原创 451. 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-10 08:54:39 185
原创 274. H-Index
Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.According to the definition of h-index on Wikipedia: "A
2017-03-09 10:14:13 295
原创 94. Binary Tree Inorder Traversal
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 solu
2017-03-09 09:20:56 192
转载 JAVA 二叉树遍历
package edu.cumt.jnotnull; import java.util.Stack; public class BinaryTree { protected Node root; public BinaryTree(Node root) { this.root = root; } p
2017-03-09 09:06:19 254
原创 311. Sparse Matrix Multiplication
Given two sparse matrices A and B, return the result of AB.You may assume that A's column number is equal to B's row number.Example:A = [ [ 1, 0, 0], [-1, 0, 3]]B = [ [ 7, 0, 0 ],
2017-03-09 04:02:12 266
原创 166. Fraction to Recurring Decimal
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parentheses.
2017-03-08 08:44:42 185
原创 463. Island Perimeter
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely
2017-03-08 06:01:49 263
原创 187. Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri
2017-03-08 01:55:29 167
原创 347. Top K Frequent Elements
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 ≤ number
2017-03-08 01:50:38 177
原创 36. Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille
2017-03-06 14:48:25 196
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人