随笔分类 -  leetcode

摘要:Reverse a singly linked list. 阅读全文
posted @ 2016-05-18 16:59 米开朗菠萝 阅读(124) 评论(0) 推荐(0)
摘要:Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 - 阅读全文
posted @ 2016-05-18 16:53 米开朗菠萝 阅读(144) 评论(0) 推荐(0)
摘要:Given a singly linked list, determine if it is a palindrome. Follow up:Could you do it in O(n) time and O(1) space? 阅读全文
posted @ 2016-05-18 15:29 米开朗菠萝 阅读(195) 评论(0) 推荐(0)
摘要:Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3- 阅读全文
posted @ 2016-05-17 22:25 米开朗菠萝 阅读(222) 评论(0) 推荐(0)
摘要:Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 暴力 KMP 以后写。。 阅读全文
posted @ 2016-05-17 20:54 米开朗菠萝 阅读(201) 评论(0) 推荐(0)
摘要:Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [−2,1,−3,4,−1,2, 阅读全文
posted @ 2016-05-16 22:27 米开朗菠萝 阅读(126) 评论(0) 推荐(0)
摘要:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or 阅读全文
posted @ 2016-05-16 21:32 米开朗菠萝 阅读(145) 评论(0) 推荐(0)
摘要:Given an array of integers, every element appears three times except for one. Find that single one. Note:Your algorithm should have a linear runtime c 阅读全文
posted @ 2016-05-15 21:47 米开朗菠萝 阅读(163) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2016-05-15 20:28 米开朗菠萝 阅读(229) 评论(0) 推荐(0)
摘要:Given an array of integers, every element appears twice except for one. Find that single one. Note:Your algorithm should have a linear runtime complex 阅读全文
posted @ 2016-05-15 19:58 米开朗菠萝 阅读(146) 评论(0) 推荐(0)
摘要: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 r 阅读全文
posted @ 2016-05-15 19:47 米开朗菠萝 阅读(209) 评论(0) 推荐(0)
摘要:Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For exa 阅读全文
posted @ 2016-05-15 16:20 米开朗菠萝 阅读(189) 评论(0) 推荐(0)
摘要:Given an integer, write a function to determine if it is a power of two. 2的幂数二进制只有一个1 阅读全文
posted @ 2016-05-11 22:16 米开朗菠萝 阅读(108) 评论(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 cl 阅读全文
posted @ 2016-05-11 22:10 米开朗菠萝 阅读(170) 评论(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 @ 2016-05-11 21:40 米开朗菠萝 阅读(130) 评论(0) 推荐(0)
摘要:Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. For example, giv 阅读全文
posted @ 2016-05-11 21:17 米开朗菠萝 阅读(135) 评论(0) 推荐(0)
摘要: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: 阅读全文
posted @ 2016-05-11 20:49 米开朗菠萝 阅读(128) 评论(0) 推荐(0)
摘要:You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 ston 阅读全文
posted @ 2016-05-11 20:15 米开朗菠萝 阅读(166) 评论(0) 推荐(0)
摘要: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 fa 阅读全文
posted @ 2016-05-11 08:41 米开朗菠萝 阅读(133) 评论(0) 推荐(0)
摘要:Write a function that takes a string as input and returns the string reversed. Example:Given s = "hello", return "olleh". 阅读全文
posted @ 2016-05-10 22:31 米开朗菠萝 阅读(118) 评论(0) 推荐(0)