- 博客(34)
- 资源 (1)
- 收藏
- 关注
原创 ERI读书笔记01 computing the parity of a word
题目是这样的:The parity of a binary word is 1 if the number of 1s is odd, otherwise, it is 0.大意就是要统计二进制中1的个数是奇数还是偶数。当然,先想到的是暴力求解法:public static short parity (long x) { short result = 0;
2016-06-30 05:36:54 322
原创 Lintcode_32 Minimum Window Substring
Given a string source and a string target, find the minimum window in source which will contain all the characters in target.ClarificationShould the characters in minimum window has the sa
2016-06-29 04:16:17 261
原创 Lintcode_30 Insert Interval
Given a non-overlapping interval list which is sorted by start point.Insert a new interval into it, make sure the list is still in order and non-overlapping (merge intervals if necessary).Ex
2016-06-28 14:23:59 247
原创 Lintcode_29 Interleaving String
Given three strings: s1, s2, s3, determine whether s3 is formed by the interleaving of s1 ands2.ExampleFor s1 = "aabcc", s2 = "dbbca"When s3 = "aadbbcbcac", return true.When s3 = "
2016-06-28 08:03:45 294
原创 Lintcode_28 Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix.This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each
2016-06-28 07:54:52 198
原创 Lintcode_18 Subsets II
Given a list of numbers that may has duplicate numbers, return all possible subsetsExampleIf S = [1,2,2], a solution is:[ [2], [1], [1,2,2], [2,2], [1,2], []]不多说了直接上代码:
2016-06-28 07:25:00 204
原创 Lintcode_16 Permutations II
Given a list of numbers with duplicate number in it. Find all unique permutations.ExampleFor numbers [1,2,2] the unique permutations are:[ [1,2,2], [2,1,2], [2,2,1]]思路是转化为字符串(中间加“
2016-06-28 07:21:25 208
原创 Lintcode_11 Search Range in Binary Search Tree
Given two values k1 and k2 (where k1 < k2) and a root pointer to a Binary Search Tree. Find all the keys of tree in range k1 to k2. i.e. print all x such that k1ExampleIf k1 = 10 and k2 =
2016-06-28 07:15:51 182
原创 Lintcode_7 Binary Tree Serialization
Design an algorithm and write code to serialize and deserialize a binary tree. Writing the tree to a file is called 'serialization' and reading back from the file to reconstruct the exact same binary
2016-06-26 12:56:09 236
原创 lintcode_2 Trailing Zeros
Write an algorithm which computes the number of trailing zeros in n factorial.Example11! = 39916800, so the out should be 2思路是统计2和5的个数,5出现的次数明显比2少,所以统计5 的个数便可~class Solution {public:
2016-06-26 12:33:21 212
原创 java表达式问题 十六进制的趣事
看下面的程序:public class test { public static void main(String[] args) { System.out.println( Long.toHexString(0x100000000L + 0xcafebabe) ); }}不会输出所想要的结
2016-06-21 07:42:54 235
原创 java表达式问题 初级问题
看看下面的程序输出是多少?public class test { public static void main(String[] args) { System.out.println( 12345+5432l ); }}不是66666,而是1777。原因是5432后面那个不是1,而是表示长整型的L的小写字母,很难区分。所以设计到长整形时,一定
2016-06-21 06:23:27 168
原创 java表达式问题 长整除
考虑两个long类型整除,以下结果会溢出:public class p3 { public static void main(String[] args) { final long MICRO_PER_DAY=24*60*60*1000*1000; final long MILLIS_PER_DAY=24*60*60*1000;
2016-06-21 06:14:13 375
转载 leecode_338 Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:Fornum
2016-06-18 14:35:05 234
原创 leecode_324 Wiggle Sort II
Given an unsorted arraynums, reorder it such that nums[0] nums[2] .Example:(1) Givennums = [1, 5, 1, 1, 6, 4], one possible answer is [1, 4, 1, 5, 1, 6].(2) Givennums = [1, 3,
2016-06-18 04:35:33 279
原创 leecode_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,4
2016-06-18 04:00:09 260
原创 leecode_322 Coin Change
You are given coins of different denominations and a total amount of moneyamount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of mon
2016-06-17 06:32:49 261
原创 leecode_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
2016-06-17 05:03:32 170
转载 leecode_342 Power of Four
Given an integer (signed 32 bits), write a function to check whether it is a power of 4.Example:Given num = 16, return true. Given num = 5, return false.Follow up: Could you solve it without
2016-06-16 04:53:02 188
原创 leecode_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,
2016-06-14 14:36:26 311
原创 leecode_310 Minimum Height Trees
For a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with minimum height are called mini
2016-06-14 13:13:21 373
原创 leecode_309 Best Time to Buy and Sell Stock with Cooldown
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on
2016-06-14 09:10:08 175
原创 leecode_307 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) function modifies nums by updating the element at index i to val.Examp
2016-06-14 04:23:59 267
原创 leecode_300 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], ther
2016-06-12 07:19:45 252
原创 leecode_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 =
2016-06-10 06:30:32 181
原创 leecode_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
2016-06-10 04:10:42 193
原创 leecode_260 Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given
2016-06-10 04:02:20 225
原创 leecode_241 Different Ways to Add Parentheses
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +,- and *.Example 1
2016-06-10 03:50:40 196
原创 leecode_240 Search a 2D Matrix II
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right.Integers in
2016-06-09 05:44:33 172
原创 leecode_236 Lowest Common Ancestor of a Binary Tree
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two node
2016-06-08 03:55:13 200
原创 leecode_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 fille
2016-06-07 02:56:27 182
原创 leecode_221 Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0
2016-06-06 11:05:49 171
原创 leecode_220 Contains Duplicate III
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i an
2016-06-02 11:31:12 251
原创 leecode_18 4Sum (k Sum)
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Element
2016-06-01 16:10:04 214
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人