随笔分类 -  算法&Leetcode

摘要: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()... 阅读全文
posted @ 2015-12-05 22:05 0giant 阅读(159) 评论(0) 推荐(0) 编辑
摘要:Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to u... 阅读全文
posted @ 2015-12-03 17:15 0giant 阅读(159) 评论(0) 推荐(0) 编辑
摘要:Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.Credits:Special thanks to ... 阅读全文
posted @ 2015-11-29 15:39 0giant 阅读(148) 评论(0) 推荐(0) 编辑
摘要:Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at... 阅读全文
posted @ 2015-11-26 12:38 0giant 阅读(144) 评论(0) 推荐(0) 编辑
摘要: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 yo... 阅读全文
posted @ 2015-11-26 10:23 0giant 阅读(192) 评论(0) 推荐(0) 编辑
摘要:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for... 阅读全文
posted @ 2015-11-25 14:46 0giant 阅读(158) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For e... 阅读全文
posted @ 2015-11-25 10:53 0giant 阅读(174) 评论(0) 推荐(0) 编辑
摘要:Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't mat... 阅读全文
posted @ 2015-11-23 19:20 0giant 阅读(145) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ ... 阅读全文
posted @ 2015-11-23 13:58 0giant 阅读(211) 评论(0) 推荐(0) 编辑
摘要: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... 阅读全文
posted @ 2015-11-23 11:08 0giant 阅读(166) 评论(0) 推荐(0) 编辑
摘要:Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front o... 阅读全文
posted @ 2015-11-22 22:03 0giant 阅读(195) 评论(0) 推荐(0) 编辑
摘要:Given an integer, write a function to determine if it is a power of two.Credits:Special thanks to @jianchao.li.fighter for adding this problem and cre... 阅读全文
posted @ 2015-11-22 22:01 0giant 阅读(152) 评论(0) 推荐(0) 编辑
摘要: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... 阅读全文
posted @ 2015-11-19 17:40 0giant 阅读(190) 评论(0) 推荐(0) 编辑
摘要:You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you cli... 阅读全文
posted @ 2015-11-19 15:24 0giant 阅读(124) 评论(0) 推荐(0) 编辑
摘要:Given a sorted linked list, delete all duplicates such that each element appear only once.For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3... 阅读全文
posted @ 2015-11-18 14:10 0giant 阅读(166) 评论(0) 推荐(0) 编辑
摘要:Reverse a singly linked list对于这种可以修改值的,把值逆序就可以了。。。。用vector存,然后逆序读。都忘了指针怎么赋值初始化了。*p=&head; 1 /** 2 * Definition for singly-linked list. 3 * struct Li... 阅读全文
posted @ 2015-11-17 19:03 0giant 阅读(158) 评论(0) 推荐(0) 编辑
摘要:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.题目虽短,但是难度还是在那里的。首先,我们需要明白罗马数字是怎么计数的,当你明白了这个就... 阅读全文
posted @ 2015-11-17 17:03 0giant 阅读(210) 评论(0) 推荐(0) 编辑
摘要:Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the ... 阅读全文
posted @ 2015-11-16 16:12 0giant 阅读(201) 评论(0) 推荐(0) 编辑
摘要:Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit i... 阅读全文
posted @ 2015-11-16 10:23 0giant 阅读(157) 评论(0) 推荐(0) 编辑
摘要:Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the arr... 阅读全文
posted @ 2015-11-13 13:13 0giant 阅读(179) 评论(0) 推荐(0) 编辑