上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 23 下一页
摘要: 题目来源:《剑指offer》面试题40 题目:一个整形数组除了两个数字之外,其他的数字都出现了两次。请写程序找出这两个只出现一次的数字。要求时间复杂度O(n),空间复杂度O(1) 分析:运用异或的思想。我们从头到尾一次异或数组中的每一个数字,那么最终得到的结果就是两个只出现一次的数字的异或结... 阅读全文
posted @ 2015-09-04 21:04 vincently 阅读(429) 评论(0) 推荐(0) 编辑
摘要: Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.Yo... 阅读全文
posted @ 2015-09-04 15:24 vincently 阅读(229) 评论(0) 推荐(0) 编辑
摘要: Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, ... 阅读全文
posted @ 2015-09-03 23:49 vincently 阅读(217) 评论(0) 推荐(0) 编辑
摘要: Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1相似题目:《剑指offer》面试题19/** * Definition for... 阅读全文
posted @ 2015-09-03 23:07 vincently 阅读(167) 评论(0) 推荐(0) 编辑
摘要: 题目来源:《剑指offer》面试题30 题目:输入n个整数,找出其中最小的k个数。例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1、2、3、4. 解法一:利用快速排序Partition的思想来解决这个问题。如果基于数组的第k个数字来调整,使得比第k个数字小的所有数字都位... 阅读全文
posted @ 2015-09-03 22:55 vincently 阅读(240) 评论(0) 推荐(0) 编辑
摘要: 题目来源:《剑指offer》面试题31、《编程之美》2.14 题目:输入一个整形数组,数组里有正数也有负数。数组中一个或连续多个整数组成一个子数组。求所有子数组的和的最大值 解法一:假设id代表自序列的一个起点,j代表终点。如果a[i]是负的,那么它不可能代表最优子序列的起点,因为任何包含a... 阅读全文
posted @ 2015-09-03 21:34 vincently 阅读(182) 评论(0) 推荐(0) 编辑
摘要: Given an array of sizen, find the majority element. The majority element is the element that appears more than⌊ n/2 ⌋times.You may assume that the arr... 阅读全文
posted @ 2015-09-03 17:58 vincently 阅读(173) 评论(0) 推荐(0) 编辑
摘要: Reverse a singly linked list. 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ... 阅读全文
posted @ 2015-09-03 15:14 vincently 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 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:... 阅读全文
posted @ 2015-09-02 16:46 vincently 阅读(189) 评论(0) 推荐(0) 编辑
摘要: Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's ... 阅读全文
posted @ 2015-09-02 15:36 vincently 阅读(178) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 23 下一页