LeetCode
糖梦梦是女侠
路漫漫其修远兮,吾将上下而求索。
展开
-
【LeetCode】8. String to Integer (atoi) 字符串转换为整数
题目: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourse原创 2016-03-29 14:10:00 · 439 阅读 · 0 评论 -
【LeetCode】141.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?理解: 在不用额外空间的情况下,判断一个链表中是否有环。分析:原创 2016-05-05 17:25:58 · 508 阅读 · 0 评论 -
【LeetCode】226. Invert Binary Tree 二叉树翻转
题目:理解:将二叉树的左右子树进行交换。代码:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), le原创 2016-04-18 13:51:15 · 294 阅读 · 0 评论 -
【LeetCode】258. 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: 3 + 8原创 2016-04-18 12:34:39 · 315 阅读 · 0 评论 -
【LeetCode】104. 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 leaf node.理解:原创 2016-04-18 13:23:37 · 338 阅读 · 0 评论 -
【LeetCode】202. Happy Number
题目: 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, replace th原创 2016-04-27 16:23:28 · 445 阅读 · 0 评论 -
【LeetCode】263. Ugly Number 丑数判断
题目: 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 example,6, 8 are ugly while原创 2016-04-27 13:38:17 · 383 阅读 · 0 评论 -
【LeetCode】6.ZigZag Conversion N型排列问题
题目: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility).原创 2016-03-23 15:09:58 · 458 阅读 · 0 评论 -
【LeetCode】131.Palindrome Partitioning回文划分
题目: 理解:即将一个字符串划分成回文子串,穷举所有的可能。分析: 由我的【LeetCode】 5.Longest Palindromic Substring最长回文子串问题 这篇文章分析可知,判断回文子串的问题可以转换为一个动态规划的问题,这里我使用了动态规划来找到所有的回文子串,将其记录到一个二维数组中,然后将这个数原创 2016-03-22 20:23:11 · 726 阅读 · 0 评论 -
【LeetCode】7.Reverse Integer
题目: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321分析: 这道题目非常简单,直接上代码吧。注意的是整数翻转后很有可能溢出,因此需要进行溢出判断。这里我设置了一个long long原创 2016-03-20 16:08:22 · 439 阅读 · 0 评论 -
【LeetCode】138.Copy List with Random Pointer 复制带有随机指针的链表
题目: A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list.翻译:给定原创 2016-03-17 13:56:29 · 3094 阅读 · 0 评论 -
【LeetCode】5.Longest Palindromic Substring 最长回文子串问题
题目: Given a string S, find the longest palindromic substring inS. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.翻译:原创 2016-03-20 16:19:57 · 692 阅读 · 2 评论 -
【LeetCode】4. Longest Substring Without Repeating Characters 最长无重复子串
题目: Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the原创 2016-03-19 18:52:01 · 395 阅读 · 0 评论 -
【LeetCode】69. Sqrt(x) 二分查找实现开平方函数
题目:翻译:即给定整数x,实现开平方函数。思路: 1.任何大于1的整数的开平方一定是大于1、小于x/2+1的,因此可以在[1,x/2+1]区间内使用二分查找来查找这个数。 2.这个题目还有一个关键问题是,若给定x非常大,计算平方时会溢出,因此数据类型应该设置为long long。题外话:在做这道题的时候,我可以根据x的原创 2016-03-16 21:35:03 · 2102 阅读 · 0 评论 -
【LeetCode】144. Binary Tree Preorder Traversal 二叉树先序遍历的非递归实现
题目:翻译:给定一个二叉树,返回先序遍历的序列。分析:二叉树的先序遍历、中序遍历及后序遍历算法是数据结构中最基础的遍历算法。 先序遍历:先访问根节点的数据,再访问左孩子节点的数据,最后访问右孩子节点的数据。图中例子先序遍历输出的序列为:【1,2,3】。 中序遍历:先访问左孩子节点的数据,再访问根节点的数据,最后访问右孩子节点的原创 2016-03-15 14:19:51 · 610 阅读 · 0 评论 -
【LeetCode】14. Longest Common Prefix 最长公共前缀问题
LeetCode 14. Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.翻译:找到一个字符串数组的最长公共前缀。例如:若给定字符串数组string[] strs为: aabbccdd原创 2016-03-14 21:31:21 · 2349 阅读 · 1 评论 -
【LeetCode】9. Palindrome Number回文数判断
题目: Determine whether an integer is a palindrome. Do this without extra space.理解: 在不额外使用空间的情况下判断一个数是否为回文数,即各个位上的数字对称,如:12321。分析: 由于不能使用额外的空间,因此不能使用将整数转换为原创 2016-03-30 20:57:46 · 1879 阅读 · 1 评论 -
【LeetCode】13. Roman to Integer
题目: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.理解: 给定一个罗马数字,将其转换为对应的整数。 输入范围为[1,3999]。原创 2016-04-24 13:04:18 · 333 阅读 · 0 评论