Happiness is more than pleasure without pain

你只有非常努力,才能看起来毫不费力

导航

随笔分类 -  Leetcode

Single Number II
摘要:Given an array of integers, every element appearsthreetimes except for one. Find that single one.Note:Your algorithm should have a linear runtime comp... 阅读全文

posted @ 2015-03-27 19:18 believer 阅读(145) 评论(0) 推荐(0)

Implement strStr()
摘要:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Update (2014-11-02):The si... 阅读全文

posted @ 2015-03-27 13:50 believer 阅读(141) 评论(0) 推荐(0)

Linked List Cycle
摘要://快慢指针public class Solution {public boolean hasCycle(ListNode head) {if(head==null)return false;ListNode slow=head;ListNode fast=head;do{if(fast==null... 阅读全文

posted @ 2015-03-26 22:34 believer 阅读(99) 评论(0) 推荐(0)

Search in Rotated Sorted Array
摘要:Suppose a sorted array 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).You are given a target valu... 阅读全文

posted @ 2015-03-22 14:17 believer 阅读(120) 评论(0) 推荐(0)

Two Sum
摘要:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two nu... 阅读全文

posted @ 2015-01-08 10:53 believer 阅读(157) 评论(0) 推荐(0)

leetcode难度及面试频率
摘要:转载自:LeetCode Question Difficulty Distribution1Two Sum25arraysortsetTwo Pointers2Add Two Numbers34linked listTwo PointersMath3Longest Substring Without... 阅读全文

posted @ 2014-10-18 09:23 believer 阅读(187) 评论(0) 推荐(0)

Search in Rotated Sorted Array
摘要:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).You are given a target value t... 阅读全文

posted @ 2014-10-18 09:12 believer 阅读(127) 评论(0) 推荐(0)

Remove Duplicates from Sorted Array II
摘要:Follow up for "Remove Duplicates":What if duplicates are allowed at mosttwice?For example,Given sorted array A =[1,1,1,2,2,3],Your function should ret... 阅读全文

posted @ 2014-10-17 12:31 believer 阅读(148) 评论(0) 推荐(0)

RemoveDuplicatesfromSortedArray
摘要:Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra space for a... 阅读全文

posted @ 2014-10-16 22:08 believer 阅读(131) 评论(0) 推荐(0)

Reverse Integer
摘要:import java.util.*;public class Solution { public static int reverse(int x) { int a=x,tmp=0,i; int []b=new int[32]; for(i=0;i=0;j--){ tmp+=b[j]... 阅读全文

posted @ 2014-09-20 10:04 believer 阅读(111) 评论(0) 推荐(0)

Maximum Depth of Binary Tree
摘要:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le... 阅读全文

posted @ 2014-09-20 08:34 believer 阅读(76) 评论(0) 推荐(0)

Same Tree
摘要:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical an... 阅读全文

posted @ 2014-09-17 07:17 believer 阅读(102) 评论(0) 推荐(0)

SingleNumber
摘要:Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity... 阅读全文

posted @ 2014-09-16 22:59 believer 阅读(94) 评论(0) 推荐(0)

动态规划求最大子段和
摘要://如果sum>Max 则更新Max//如果sumMax)Max=sum; if(sum<0)sum=0;}//貌似双指针法,Max指针指向全局最大,sum指针移动,找到更大的则赋给Max,Max始终指向了全局最大 阅读全文

posted @ 2014-09-10 08:46 believer 阅读(254) 评论(0) 推荐(0)