- 博客(19)
- 资源 (1)
- 收藏
- 关注
原创 leetcode Multiply Strings
Multiply Strings Total Accepted: 1717 Total Submissions: 9415My SubmissionsGiven two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers
2013-11-28 23:23:34 599
原创 leetcode Validate Binary Search Tree
Validate Binary Search Tree Total Accepted: 3218 Total Submissions: 12801My SubmissionsGiven a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined
2013-11-27 20:44:36 919
原创 leetcode Clone Graph
Clone Graph Total Accepted: 2649 Total Submissions: 14045My SubmissionsClone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirecte
2013-11-27 15:59:49 1223
原创 leetcode Substring with Concatenation of All Words
You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without an
2013-11-26 20:05:45 996
原创 leetcode Copy List with Random Pointer
Take advantage of the original list, but there is a WA code. Don't break the structure after allocate the random pointers. /** * Definition for singly-linked list with a random pointer. * struct R
2013-11-24 17:17:05 880
原创 leetcode Linked List Cycle II
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?A fast pointer (hare) moves two steps ever
2013-11-24 16:18:44 869
原创 leetcode 143 Reorder List 单链表
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution { public: ListNode* rev
2013-11-24 15:59:35 976
原创 leetcode Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recursive solut
2013-11-23 10:18:00 1211
转载 正确使用stl map的erase方法
STL的map表里有一个erase方法用来从一个map中删除掉指令的节点eg:mapstring,string> mapTest;typedef mapstring,string>::iterator ITER;ITER iter=mapTest.find(key);mapTest.erase(iter); 像上面这样只是删除单个节点,map的形为不会出现任
2013-11-21 15:50:01 857
原创 leetcode Gas Station
Two problems :1. The car won't travel anticlockwise.2. Use i = i + j to speed up the calculation. class Solution { public: int canCompleteCircuit(vector &gas, vector &cost) { int i, j, le
2013-11-19 23:03:17 1407
原创 leetcode Regular Expression Matching
This problem is a good contrast to Wildcard Matching. Both DP and recursive program could finish it except greedy algorithm. DP:class Solution { public: bool isMatch(const char *s, const char *
2013-11-16 13:04:02 1527
原创 leetcode 75. Sort Colors 荷兰国旗
Given an array withnobjects colored red, white or blue, sort themin-placeso that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the in...
2013-11-14 20:42:25 814
原创 leetcode Minimum Window Substring
Double pointers, greedy algorithms are obvious, however, I wrote a disgusting code like this:class Solution { public: string minWindow(string S, string T) { map Tmap; if (T.length() == 0)
2013-11-14 12:33:54 951
原创 LeetCode 54. Spiral Matrix 剑指 Offer 29. 顺时针打印矩阵
Take control of the 4 key points:class Solution { public: vector spiralOrder(vector > &matrix) { vector res; int rownum = matrix.size(), colnum = matrix.size() ? matrix[0].size() : 0, i,
2013-11-13 13:16:09 944
原创 leetcode First Missing Positive
swapclass Solution { public: int firstMissingPositive(int A[], int n) { int i, An = 0; for (i = 0; i < n; ++i) while (A[i] != i) if (A[i] >= 0 && A[i] < n && A[A[i]] != A[
2013-11-12 22:24:58 1142
原创 leetcode Interleaving String
First, I wrote a DFS program using a stack, however, TLEclass Solution { public: bool isInterleave(string s1, string s2, string s3) { int i = 0, j = 0, k = 0; stack s3stack, s2stack;
2013-11-12 21:16:57 901
原创 leetcode String to Integer (atoi)
Requirements for atoi:The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optiona
2013-11-10 23:09:37 882
原创 leetcode Median of Two Sorted Arrays
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)).Best Solution by Binary Search:Be...
2013-11-10 16:05:29 886
原创 leetcode Longest Palindromic Substring Part II
Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one unique longest palindromic substring.There is little to sa...
2013-11-05 17:13:26 1230
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人