- 博客(18)
- 资源 (4)
- 问答 (2)
- 收藏
- 关注
原创 Lowest Common Ancestor of a Binary Search Tree
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: “The lowest common ancestor is defined between two
2015-07-26 22:34:54 179
原创 Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.You
2015-07-26 21:09:07 318
原创 Implement strStr()
即:自己实现strstr()函数 Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.解题思路: 求出两个函数的长度差值,即返回值index的取值范围int strStr(char* haystack,
2015-07-23 22:55:03 184
原创 Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.解题思路: (1)重新分配一个数组,大小为digitsS
2015-07-22 21:23:25 336
原创 Sort List
Sort a linked list in O(n log n) time using constant space complexity.解题思路: (1)将链表中的值依次取出存在一个数组中 (2)对数组进行希尔排序 (3)将排序后的元素放回链表中struct ListNode* sortList(struct ListNode* head) {struct ListNode* head1
2015-07-21 22:07:23 273
原创 Reverse Linked List
给定一个链表:1->2->3->NULL 反转后为:3->2->1->NULL;struct ListNode* reverseList(struct ListNode* head) { struct ListNode* pNode = head; struct ListNode* PreNode = NULL; struct ListNode* NewHead =
2015-07-21 21:32:00 298
原创 Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->6->NULL, m = 2 and n = 5, return 1->5->4->3->2->6->NULL. Note: Given m, n satisfy the
2015-07-21 21:28:55 246
原创 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be very large,
2015-07-21 11:48:57 296
原创 4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: Elements in a quad
2015-07-20 15:45:30 324
原创 3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: Elements in a triplet (a,b,c) must be
2015-07-20 13:40:01 411
原创 Two Sum
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 in
2015-07-19 23:18:11 252
原创 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly
2015-07-19 22:48:19 421
原创 求旋转数组的最小值
已知一个递增排序的旋转数组(没有重复的数),如{1,2,3,4,5}的一个旋转数组为{3,4,5,1,2},求旋转数组的最小值解题思路:(1)第一个指针总是指向前面的递增数组,最终停在最大的元素上,即元素5; (2)第二个指针总是指向后面的递增数组,最终停在最小的元素上,即元素1int findMin(int* nums, int numsSize) {int start = 0;int end
2015-07-17 23:12:20 484
原创 将一个链表后K个结点移到链表头
例如:给定链表: 1->2->3->4->5->NULL ; k = 2或k = 7 翻转后的结果为: 4->5->1->2->3->NULL.解题思路:(1)将单链表转换成循环链表 (2)根据K值确定新链表头的位置struct ListNode* rotateRight(struct ListNode* head, int k) {if (head == NULL || k == 0)
2015-07-15 21:55:44 572
原创 求一个二叉搜索树中第K个最小值
假设该颗二叉搜索树的总元素数大于等于K解题思路:用STL容器的栈来实现int kthSmallest(TreeNode* root, int k) { std::stack<TreeNode*> Stack; while (root || !Stack.empty()) { if (root) { Stack.push
2015-07-14 22:51:16 997
原创 字符串的无重复全排列
using namespace std;void function(char* pStr, char* pBegin); bool IsSwap(char* pBegin, char* pEnd);int main(void) {char str[] = "aabc";function(str,str);return 0;}//在[pBegin,pEnd]区间中是否有字符与下标为pEnd的字符
2015-07-09 16:58:49 681
原创 arm-linux-gcc交叉编译器安装说明
Arm-linux-gcc 交叉编译器安装使用说明: 1. 解压安装包:#tar xvf arm-linux-gcc-3.4.1.tar.bz2 –C / 2. 进入解压后的文件夹,将以交叉编译器版本号命名的文件夹拷贝到/usr/local/目录下,则现在的交叉编译程序集都在/usr/local/3.4.1/bin里面 3. 修改环境变量,把交叉编译器的路径加入到PATH:修改~/.ba
2015-07-04 15:00:33 550
原创 求一个字符串中不带重复字母的最长substr的长度
问题描述:给出一个字符串,求该字符串的最长子字符串的长度,该子字符串没有重复的字符。例如:给定字符串“abcabca”,则返回的长度应该为3;再如给定字符串“aaaaaaaa”,则返回测长度应该为1.解题思路:用一个临时字符串来存储当前字符串的没有重复字符的子字符串 int lengthOfLongestSubstring(char* s) { if (s == NULL)
2015-07-02 22:29:35 557
Convert To Renex
2013-11-14
注释掉printf语句程序出现段错误
2015-12-25
攻击者能够欺骗 DNS,如何解决?
2014-12-12
TA创建的收藏夹 TA关注的收藏夹
TA关注的人