上一页 1 2 3 4 5 6 ··· 11 下一页
摘要: class rw_lock_t { int NoOfReaders; int NoOfWriters, NoOfWritersWaiting; pthread_mutex_t class_mutex; pthread_cond_t reader_gate; pthread_cond_t writer_gate;public: rw_lock_t() : NoOfReaders(0), NoOfWriters(0), NoOfWritersWating(0), class_mutex(PTHREAD_MUTEX_INITIALIZER), ... 阅读全文
posted @ 2013-08-01 17:40 一只会思考的猪 阅读(281) 评论(0) 推荐(0) 编辑
摘要: 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 order.You may assume no duplicates in the array. Here are few examples. [1,3,5,6], 5 → 2 [1,3,5,6], 2 → 1 [1,3,5,6], 7 → 4 [1,3,5,6], 0 → 0class Solutio 阅读全文
posted @ 2013-07-17 08:40 一只会思考的猪 阅读(98) 评论(0) 推荐(0) 编辑
摘要: The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, ... 1 is read off as "one 1" or 11. 11 is read off as "two 1s" or 21. 21 is read off as "one 2, then one 1" or 1211. Given an integer n, generate the nth sequence. Note 阅读全文
posted @ 2013-07-17 08:25 一只会思考的猪 阅读(176) 评论(0) 推荐(0) 编辑
摘要: Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2. Your algorithm should run in O(n) time and uses constant space.题意是是说:在正整数的范围里面求第一个缺失的数A[0] = 1 A[1] = 2....A[i] = i+1; 正确的存储.此题目没有好好解答出来。再思考。class Solution {public: 阅读全文
posted @ 2013-07-16 23:23 一只会思考的猪 阅读(167) 评论(0) 推荐(0) 编辑
摘要: Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example, Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]You should return [1,2,3,6,9,8,7,4,5].//DFS 版本//之后需要设计一个非递归的版本//甚至给定(i,j)推断给定位置的valueclass Solution {public: voi... 阅读全文
posted @ 2013-07-16 23:01 一只会思考的猪 阅读(163) 评论(0) 推荐(0) 编辑
摘要: Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit string "23"Output: ["ad", "ae", "af", "bd", "be", &q 阅读全文
posted @ 2013-07-14 19:44 一只会思考的猪 阅读(238) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5. Note: Given n will always be valid. Try to do this in one 阅读全文
posted @ 2013-07-14 18:20 一只会思考的猪 阅读(135) 评论(0) 推荐(0) 编辑
摘要: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.class Solution {public: struct Node{ ListNode *p; Node(ListNode* pointer):p(pointer){ } //make heap的时候,k和2k 2k+1的孩子比较,这样就会采用 rs.p->val bool operator val > rs.p-... 阅读全文
posted @ 2013-07-14 18:07 一只会思考的猪 阅读(182) 评论(0) 推荐(0) 编辑
摘要: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and "([)]&qu 阅读全文
posted @ 2013-07-14 17:51 一只会思考的猪 阅读(187) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed.class Solution 阅读全文
posted @ 2013-07-14 16:59 一只会思考的猪 阅读(156) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 11 下一页