
数据结构与算法
Joy-Coder
认真、严谨、求实、求是
展开
-
Symmetric Tree算法详解
算法题目:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: But the following is not: Note: Bonus points if you c原创 2015-06-22 10:57:28 · 558 阅读 · 0 评论 -
Add Binary 算法详解
算法题目:Given two binary strings, return their sum (also a binary string).For example, a = “11” b = “1” Return “100”大致意思:二进制字符串的加法解题思路:可以用循环与递归来求解循环版本: string addBinary(string a, string b) {原创 2015-06-22 22:47:52 · 741 阅读 · 0 评论 -
Read N Characters Given Read4算法详解
算法题目:The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters left in t原创 2015-06-23 17:36:26 · 666 阅读 · 0 评论 -
Two Sum III - Data structure design数据结构设计
算法题目:Design and implement a TwoSum class. It should support the following operations: add and find.add - Add the number to an internal data structure. find - Find if there exists any pair of numbers w原创 2015-06-23 17:07:32 · 1316 阅读 · 0 评论 -
Merge Sorted Array算法详解
算法题目:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold addit原创 2015-06-22 11:47:36 · 458 阅读 · 0 评论 -
Balanced Binary Tree 算法详解
算法题目:Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe原创 2015-06-21 16:03:06 · 1098 阅读 · 0 评论 -
LeetCode:Valid Parentheses算法详解
算法题目:Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid. The brackets must close in the correct order, “()” 、 “()[]{}” and “([])[{()原创 2015-06-20 17:10:17 · 354 阅读 · 0 评论 -
LeetCode: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 two endpoints of line i is at (i, ai) and (i, 0). Find tw原创 2015-06-20 12:24:26 · 545 阅读 · 0 评论 -
Path Sum算法详解
算法题目:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example: Given the below binary tree and su原创 2015-06-21 11:01:51 · 867 阅读 · 0 评论 -
HashMap的简单实现,具有线程安全
hashmap实现原创 2015-08-21 11:49:48 · 1795 阅读 · 0 评论