1 2 3 4 5 ··· 11 下一页
摘要: public class Iterative { /** Normal Binary Search for sorted array like : 1,2,3,4,5,6,7,8,9,10,11 Complexity: O(LogN) PS: element can be duplicated */ static public int binarySearch(int[] array, int target){ int left = 0, right = array.length - 1; while (left target)... 阅读全文
posted @ 2013-11-06 14:23 一只会思考的猪 阅读(262) 评论(0) 推荐(0) 编辑
摘要: static int tree_height(const Node* root, int& max_distance){ const int left_height = root->left ? tree_height(root->left, max_distance) + 1 : 0; const int right_height = root->right ? tree_height(root->right, max_distance) + 1 : 0; const int distance = left_height + right_height; if 阅读全文
posted @ 2013-09-17 23:07 一只会思考的猪 阅读(175) 评论(0) 推荐(0) 编辑
摘要: Follow up for "Search in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the array.class Solution {public: bool help(int *a,int from,int to,int x) { if (from > to) { r... 阅读全文
posted @ 2013-09-15 15:35 一只会思考的猪 阅读(166) 评论(0) 推荐(0) 编辑
摘要: Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).You are given a target value to search. If found in the array return its index, otherwise return -1.You may assume no duplicate exists in the array. int rotateSearch(int A[], in... 阅读全文
posted @ 2013-09-15 15:15 一只会思考的猪 阅读(180) 评论(0) 推荐(0) 编辑
摘要: Reverse Number without extra spaceclass Solution {public: bool isPalindrome(int x) { // Start typing your C/C++ solution below // DO NOT write int main() function if (x 9; y /= 10, w *= 10) ; for (;w > 1; w /= 100) { //去掉2位所有 w/=100 if (x % 10 != x /... 阅读全文
posted @ 2013-09-09 22:36 一只会思考的猪 阅读(172) 评论(0) 推荐(0) 编辑
摘要: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.这题目是:是Largest Rectangle in Hisgoram的升级版本。 只要那个问题解决了,然后for int i = 0 to i > &matrix) { // Start typing your C/C++ solution below // DO NOT write int main() functio... 阅读全文
posted @ 2013-09-04 14:21 一只会思考的猪 阅读(223) 评论(0) 推荐(0) 编辑
摘要: Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of each bar is 1, given height =[2,1,5,6,2,3].The largest rectangle is shown in the shaded area, which has ar 阅读全文
posted @ 2013-09-04 14:05 一只会思考的猪 阅读(153) 评论(0) 推荐(0) 编辑
摘要: Given an integern, generate a square matrix filled with elements from 1 ton2in spiral order.For example,Givenn=3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ]]class Solution {public: vector > generateMatrix(int n) { // Start typing your C/C++ solution below... 阅读全文
posted @ 2013-09-03 23:12 一只会思考的猪 阅读(163) 评论(0) 推荐(0) 编辑
摘要: Givens1,s2,s3, find whethers3is formed by the interleaving ofs1ands2.For example,Given:s1="aabcc",s2="dbbca",Whens3="aadbbcbcac", return true.Whens3="aadbbbaccc", return false.#include #include #include /**Given s1, s2, s3, find whether s3 is formed by the int 阅读全文
posted @ 2013-08-27 22:50 一只会思考的猪 阅读(510) 评论(0) 推荐(0) 编辑
摘要: http://fihopzz.blogspot.com/2013/07/enter-post-title-here-binary-search-and.html 阅读全文
posted @ 2013-08-01 18:10 一只会思考的猪 阅读(120) 评论(0) 推荐(0) 编辑
1 2 3 4 5 ··· 11 下一页