随笔分类 -  leetcode

Length of Last Word
摘要:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word 阅读全文

posted @ 2017-12-19 15:42 夜的第八章 阅读(122) 评论(0) 推荐(0)

Maximum Subarray(最大子数组)
摘要: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 @ 2017-12-19 15:25 夜的第八章 阅读(185) 评论(0) 推荐(0)

count-and-say
摘要:The count-and-say sequence is the sequence of integers with the first five terms as following: 1 is read off as "one 1" or 11.11 is read off as "two 1 阅读全文

posted @ 2017-12-19 14:55 夜的第八章 阅读(456) 评论(0) 推荐(0)

Search Insert Position
摘要: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 @ 2017-12-19 11:12 夜的第八章 阅读(116) 评论(0) 推荐(0)

remove element
摘要:Given an array and a value, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you 阅读全文

posted @ 2017-12-19 10:05 夜的第八章 阅读(128) 评论(0) 推荐(0)

Remove Duplicates from Sorted Array
摘要: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 fo 阅读全文

posted @ 2017-12-18 21:05 夜的第八章 阅读(173) 评论(0) 推荐(0)

merge two sorted lists
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. Example: 阅读全文

posted @ 2017-12-18 20:11 夜的第八章 阅读(177) 评论(0) 推荐(0)

valid parentheses
摘要:parentheses:括号 Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets mus 阅读全文

posted @ 2017-12-18 19:37 夜的第八章 阅读(148) 评论(0) 推荐(0)

Longest Common Prefix
摘要:Write a function to find the longest common prefix string amongst an array of strings. 找出所有字符串中的共同字符串前缀。 方法一:让第一个字符串作为基准,遍历该字符串,依次将该字符串中的每个字符跟其他所有字符串相 阅读全文

posted @ 2017-12-18 19:01 夜的第八章 阅读(183) 评论(0) 推荐(0)

palindrome number(回文数)
摘要:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thi 阅读全文

posted @ 2017-12-18 16:30 夜的第八章 阅读(188) 评论(0) 推荐(0)

Two Sum
摘要:Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have ex 阅读全文

posted @ 2017-12-18 14:34 夜的第八章 阅读(152) 评论(0) 推荐(0)

Average of Levels in Binary Tree
摘要:Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array. Example 1: 还是应用广度优先遍历(BFS),然后计算每一层的和就行 阅读全文

posted @ 2017-12-17 13:04 夜的第八章 阅读(135) 评论(0) 推荐(0)

Array Partition I
摘要:Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of 阅读全文

posted @ 2017-12-17 12:45 夜的第八章 阅读(119) 评论(0) 推荐(0)

add digits
摘要: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 @ 2017-12-16 21:15 夜的第八章 阅读(132) 评论(0) 推荐(0)

1-bit and 2-bit Characters
摘要:We have two special characters. The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11). N 阅读全文

posted @ 2017-12-16 20:16 夜的第八章 阅读(150) 评论(0) 推荐(0)

container-with-most-water
摘要:题目: Given n non-negative integers a1 , a2 , ..., an , where each represents a point at coordinate (i, ai ). n vertical lines are drawn such that the t 阅读全文

posted @ 2017-12-13 22:05 夜的第八章 阅读(151) 评论(0) 推荐(0)

查找链表中是否有环linked-list-cycle
摘要:Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space? 不使用额外空间:这里没有实例化一个对象,只是引用对象,所以不会开辟新内存空间 用 阅读全文

posted @ 2017-12-13 20:56 夜的第八章 阅读(140) 评论(0) 推荐(0)

reverse-integer
摘要:题目: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Have you thought about this? Here are some good questi 阅读全文

posted @ 2017-12-13 20:38 夜的第八章 阅读(140) 评论(0) 推荐(0)

single-number
摘要:Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime comple 阅读全文

posted @ 2017-12-12 22:14 夜的第八章 阅读(163) 评论(4) 推荐(0)

Best Time to Buy and Sell Stock II
摘要:题目: Say you have an array for which the i th element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may c 阅读全文

posted @ 2017-12-12 21:55 夜的第八章 阅读(127) 评论(0) 推荐(0)

导航