摘要: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.set(key, value)- Set or insert the value if the key is not 阅读全文
posted @ 2014-03-01 11:38 andyqee 阅读(152) 评论(0) 推荐(0) 编辑
摘要: Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.Solution:/** * Definition for a point. * struct Point { * int x; * int y; * Point() : x(0), y(0) {} * Point(int a, int b) : x(a), y(b) {} * }; */class Solution {public: int maxPoints(v... 阅读全文
posted @ 2014-02-22 14:56 andyqee 阅读(123) 评论(0) 推荐(0) 编辑
摘要: Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another expression.Some examples: ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9 ["4", "13&qu 阅读全文
posted @ 2014-01-05 16:51 andyqee 阅读(115) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are 阅读全文
posted @ 2013-12-22 20:58 andyqee 阅读(148) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].Note:Recursive solution is trivial, could you do it iteratively?/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode... 阅读全文
posted @ 2013-12-22 16:37 andyqee 阅读(464) 评论(0) 推荐(1) 编辑
摘要: Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return6./** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * Tree... 阅读全文
posted @ 2013-12-22 09:49 andyqee 阅读(945) 评论(2) 推荐(0) 编辑
摘要: Objective-CEncapsulating Data01. atomic // default02. nonatomic03. strong=retain // default04. weak= unsafe_unretained05. retain06. assign // default07. unsafe_unretained08. copy09. readonly10. readwrite // default1.nonatomic在Objective-C ... 阅读全文
posted @ 2013-12-21 19:28 andyqee 阅读(910) 评论(0) 推荐(0) 编辑
摘要: Problem:Minimum Depth of Binary TreeGiven a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Solution one based on recursive algrithm. It looks clear, but not optimal .//Solution one /** * Definition 阅读全文
posted @ 2013-12-21 17:27 andyqee 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 这个礼拜应该算是踏上iOS学习的第一个礼拜,有必要对这段学习过程做一个简短的总结。直观感觉:iOS 开发环境给我的直观印象非常cool,XCode许多酷炫的功能,iOS 7 SDK的优良的设计,其极其丰富的api,以及Objective-C 奇特的语法让我觉得非常新鲜有趣。主要按照apple 官方的开发入门指导,完成一个 To-do—List app通过实现这个小project,简单小结:1.XCode 的开发环境, 如何通过storyboard 设计 view controller,table view controller,navigation controller,为button添加a. 阅读全文
posted @ 2013-12-12 20:58 andyqee 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 1.Java 并发编程的容器ConcurrentHashMap,HashTable,Collections.synchronizedMap 三者比较。HashTable,Collections.synchronizedMap 提供对hashmap的独占锁,当有一个线程对其remove,add,遍历,等操作时,即使cpu有空闲的资源,也不能访问该容器。可伸缩性比较差。而ConcurrentHashMap采用的颗粒更细小的锁,采用32个独立的锁对hash bucket的子集进行,那么最多就可以有32个线程进行并发访问。显然极大的提高了并发性,但是带来一个问题,如果有些操作必须使用独占访问,那该如何 阅读全文
posted @ 2013-11-30 23:19 andyqee 阅读(195) 评论(0) 推荐(0) 编辑