算法学习
氷冷酒
这个作者很懒,什么都没留下…
展开
-
LeetCode算法第7篇:235 Lowest Common Ancestor of a Binary Search Tree
问题描述: Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined be原创 2015-10-02 20:18:48 · 342 阅读 · 0 评论 -
LeetCode算法第8篇:234 Palindrome Linked List
问题描述: 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?代码实现:/** * Definition for singly-linked list. * struct ListNode { * int原创 2015-10-02 20:33:07 · 319 阅读 · 0 评论 -
LeetCode算法第1篇: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 14 is not ugly原创 2015-09-18 19:36:19 · 327 阅读 · 0 评论 -
LeetCode算法第2篇:278 First Bad Version
算法描述: You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed base原创 2015-09-18 20:08:40 · 314 阅读 · 0 评论 -
LeetCode算法第3篇: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 = 11, 1 + 1 = 2. Since 2 has only one d原创 2015-09-19 20:53:47 · 339 阅读 · 0 评论 -
LeetCode算法第4篇:257 Binary Tree Paths
问题描述: Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]代码实现:/** * Definition fo原创 2015-09-21 09:38:30 · 610 阅读 · 1 评论 -
LeetCode算法第5篇:242 Valid Anagram
问题描述: Given two strings s and t, write a function to determine if t is an anagram of s.For example, s = “anagram”, t = “nagaram”, return true. s = “rat”, t = “car”, return false.Note: You may assum原创 2015-09-22 09:18:09 · 336 阅读 · 0 评论 -
LeetCode算法第6篇:237 Delete Node in a Linked List
问题描述: 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 -> 4and you are given the third node with valu原创 2015-09-22 09:23:52 · 328 阅读 · 0 评论