2016年5月15日

Sqrt(x)

摘要: Implement int sqrt(int x). Compute and return the square root of x. 求一个数的开方,binary search on result 二分结果的典型。 对于0和1直接返回1。后面的left = 1 ,right 为 x/2。代码如下: 阅读全文

posted @ 2016-05-15 22:08 Sheryl Wang 阅读(172) 评论(0) 推荐(0) 编辑

Lowest Common Ancestor of a Binary Tree

摘要: Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowes 阅读全文

posted @ 2016-05-15 17:05 Sheryl Wang 阅读(194) 评论(0) 推荐(0) 编辑

2016年5月14日

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 c 阅读全文

posted @ 2016-05-14 22:04 Sheryl Wang 阅读(157) 评论(0) 推荐(0) 编辑

Search for a Range

摘要: Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the or 阅读全文

posted @ 2016-05-14 21:54 Sheryl Wang 阅读(123) 评论(0) 推荐(0) 编辑

Find in Large Sorted Array

摘要: http://www.lintcode.com/zh-cn/problem/search-in-a-big-sorted-array/ 给一个按照升序排序的正整数数组。这个数组很大以至于你只能通过固定的接口 ArrayReader.get(k) 来访问第k个数。(或者C++里是ArrayReade 阅读全文

posted @ 2016-05-14 21:26 Sheryl Wang 阅读(239) 评论(0) 推荐(0) 编辑

2016年5月13日

Search a 2D Matrix

摘要: Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted f 阅读全文

posted @ 2016-05-13 11:59 Sheryl Wang 阅读(129) 评论(0) 推荐(0) 编辑

2016年5月12日

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 @ 2016-05-12 22:46 Sheryl Wang 阅读(115) 评论(0) 推荐(0) 编辑

Validate Binary Search Tree

摘要: Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only 阅读全文

posted @ 2016-05-12 10:36 Sheryl Wang 阅读(153) 评论(0) 推荐(0) 编辑

2016年5月11日

Populating Next Right Pointers in Each Node II

摘要: Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any binary tree? Would your previous solution sti 阅读全文

posted @ 2016-05-11 21:47 Sheryl Wang 阅读(150) 评论(0) 推荐(0) 编辑

Populating Next Right Pointers in Each Node

摘要: Given a binary tree Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL 阅读全文

posted @ 2016-05-11 17:18 Sheryl Wang 阅读(127) 评论(0) 推荐(0) 编辑

导航