- 博客(167)
- 收藏
- 关注
原创 Evaluate Reverse Polish Notation
Catalogue:string-类型转换QuestionEvaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some
2014-12-14 09:52:11 470 1
原创 Reverse Words in a String
QuestionGiven an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".First tryclass Solution {public: void reverseWord
2014-12-13 19:06:53 374
原创 Maximum Product Subarray
Catelogue: array+动态规划Question:Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous
2014-12-13 06:14:02 324
原创 Find Minimum in Rotated Sorted Array II
Catalogue:array - 分治法QuestionSuppose 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.The array may
2014-12-13 02:07:09 502
原创 Find Minimum in Rotated Sorted Array
Catalogue: array-分治法搜索QuestionSuppose 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.
2014-12-13 01:49:16 489
原创 Min Stack
Catalogue:stackQuestionDesign a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on
2014-12-12 19:53:29 468
原创 Intersection of Two Linked Lists
Catalogue:链表-双指针QuestionWrite a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2
2014-12-11 23:26:41 350
原创 Find Peak Element
Catalogue:查找-分治法QuestionA peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may c
2014-12-11 22:13:32 436
原创 [C++]va_list、va_start、va_arg、va_end宏的使用
当你的函数的参数个数不确定时,就可以使用上述宏进行动态处理,这无疑为你的程序增加了灵活性。Example:CString AppendString(CString str1,...)//一个连接字符串的函数,参数个数可以动态变化{ LPCTSTR str=str1;//str需为指针类型,因为va_arg宏返回的是你的参数的指针,但是如果你的参数为int等简单类型,则不必为指
2014-10-01 20:12:23 523
原创 创建线程
Java(1)通过扩展Thread类来创建多线程class MutliThread extends Thread{ private int ticket=100;//每个线程都拥有100张票 MutliThread(Stringname){ super(name);//调用父类带参数的构造方法 } public void run()
2014-10-01 20:03:52 309
原创 string的操作
分割字符串PHP1. array explode(separator,string[,limit])separator:分隔符string:要分割的字符串limit:规定所返回的数组元素的最大数目。返回的最后一个子串将包含所有剩余部分。limit值为-1, 0或null时都代表"不限制" 2. array preg_split ( string $patte
2014-10-01 19:55:16 459
原创 打印
php输出echo、print、print_r、printf、sprintf、var_dump比较1. echo() 实际上不是一个函数,是php语句,因此您无需对其使用括号。如果您希望向 echo()传递一个以上的参数,那么使用括号会发生解析错误。echo返回void。2. print() 和 echo()用法一样,但是echo速度会比print快一点点。实际上它也不是一
2014-10-01 19:49:57 275
原创 各种语言基本语法
1.Python1. 变量声明不需要声明数据类型2. 函数定义3. 注释由#开始4. 其他在Python中没有switch语句,可以使用if..elif..else语句来完成同样的工作句末不一定要有分号,但如果两个语句在同一行中,则必须用分号隔开。空格表示新开语句块。不要混合使用制表符和空格来缩进2. Javascri
2014-10-01 19:46:15 454
原创 文件操作
PHP$myfile = 'wtndata/statistic.txt';$file_pointer = fopen($myfile,"a");fwrite($file_pointer,$str);fclose($file_pointer);读取行:string fgets ( int handle [, int length] )从 handle 指向的文件中读取一行
2014-10-01 19:43:14 252
原创 Catalogue of leetcode
I. Array and List------I/1.Sort------Merge Sorted ArraySort ColorsMerge Two SortedListsMerge k SortedListsLongest ConsecutiveSequenceInsertion Sort ListSort List------I/2.RejustList-
2014-09-25 08:21:19 455
原创 Sort List
------QUESTION------Sort a linked list in O(n log n)time using constant space complexity.------SOLUTION------class Solution {public: ListNode *sortList(ListNode *head) { if(!head
2014-09-25 08:17:24 276
原创 Max Points on a Line
------QUESTION------Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.------SOLUTION------
2014-09-25 08:16:24 317
原创 Insertion Sort List
------QUESTION------Sort a linked list using insertion sort.------SOLUTION------class Solution {public: ListNode *insertionSortList(ListNode *head) { if(!head || !head->next) return
2014-09-25 08:16:12 291
原创 LRU Cache
------QUESTION------Design and implement a data structure for Least Recently Used (LRU)cache. It should support the following operations: get and set.get(key) - Get the value (will always be
2014-09-25 08:14:29 363
原创 Reorder List
------QUESTION------Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given
2014-09-25 08:13:20 316
原创 Binary Tree Postorder Traversal
------QUESTION------Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [3,2,1
2014-09-24 16:45:52 305
原创 Binary Tree Preorder Traversal
------QUESTION------Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,2,3]
2014-09-24 16:44:47 265
原创 Linked List Cycle II
------QUESTION------Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?------SOLUTION--
2014-09-24 16:43:40 329
原创 Linked List Cycle
------QUESTION------Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?------SOLUTION------采用“快慢指针”查检查链表是否含有环。让一个指针一次走一步,另一个一
2014-09-24 16:42:39 302
原创 Word Break II
------QUESTION------Given a string s and a dictionary of words dict, add spaces in s to construct as entence where each word is a valid dictionary word.Return all such possible sentences.F
2014-09-24 16:42:15 287
原创 Copy List with Random Pointer
------Question------A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.------
2014-09-24 16:40:25 291
原创 Clone Graph
------Question------Clone anundirected graph. Each node in the graph containsa label anda list of its neighbors.OJ's undirected graphserialization:Nodes arelabeled uniquely.We use # asa se
2014-09-24 16:37:50 306
原创 Single Number II
-----QUESTION-----Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you im
2014-09-24 16:35:35 251
原创 Candy
-----QUESTION-----There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child
2014-09-24 16:34:54 281
原创 Word Break
-----QUESTION-----Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leet
2014-09-24 16:33:40 247
原创 Single Number
-----QUESTION-----Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implem
2014-09-24 16:32:29 267
原创 Gas Station
-----QUESTION-----There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to
2014-09-24 16:29:01 237
原创 Populating Next Right Pointers in Each Node II
------QUESTION------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 still work?Note:
2014-09-24 16:28:11 322
原创 Spiral Matrix II
class Solution {public: vector > generateMatrix(int n) { vector> matrix(n,vector(n)); if(n==0) return matrix; leftPos = 0; rightPos = matrix[0].size()-1;
2014-09-24 16:23:54 315
原创 Valid Sudoku
-----QUESTION-----Determine if a Sudoku is valid, according to: Sudoku Puzzles - TheRules.The Sudoku board could be partially filled, where empty cells are filled with the character'.'.S
2014-09-24 16:21:46 239
原创 Sudoku Solver
-----QUESTION-----Write a program to solve a Sudoku puzzle by filling the emptycells.Empty cells are indicated by thecharacter '.'.You may assume that there will be only one unique solut
2014-09-24 16:18:36 271
原创 Median of Two Sorted Arrays
-----QUESTION-----There are two sorted arrays A and B of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).-----SOLUTION-
2014-09-24 16:17:01 214
原创 Two Sum
-----QUESTION-----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 a
2014-09-24 16:15:15 234
原创 Add Two Numbers
-----QUESTION-----You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of theirnodes contain a single digit. Add the two numbers
2014-09-24 16:14:45 236
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人