- 博客(96)
- 资源 (4)
- 收藏
- 关注
原创 字符串的全排列
题目描述 输入一个字符串,打印出该字符串中字符的全排列。解法一:递归实现 从未打印字符中选择一个打印,递归打印剩余字符。具体实现:将要打印的字符移动到剩余字符串的头部,递归至没有剩余字符时一起全部打印。 C++代码:void permutation(string &str, int start){ if (start == str.size()) { cout <<
2015-12-24 19:12:00
507
原创 字符串的包含
题目描述 给定一个字符串a和一短字符串b,只包含小写字母,判断b中元素是否都在a中?a是”abcd”,b是”bad”,答案是truea是”abcd”,b是”bce”,答案是falsea是”abcd”,b是”aa”,答案是true解法一:蛮力轮询 轮询字符串b中每个字符,逐一与a中字符比较。 时间复杂度:O(nm); 空间复杂度:O(1)C++代码:bool stringContain_
2015-12-24 00:33:41
1072
原创 字符串的旋转
题目描述给定一个字符串,要求将字符串的前若干(m)位字符移动到字符串的尾部。**例如**:将字符串"abcdef"的前3个字符'a'、'b'和'c'移到字符串的尾部,得到"defabc"。解法一:n轮移动,每轮中将每个字符左移一位。 时间复杂度:O(mn); 空间复杂度:O(1)void leftRotateString_1(string &str, int m){ if (m <
2015-12-23 00:19:00
601
原创 06-图4. Saving James Bond - Hard Version (30)
06-图4. Saving James Bond - Hard Version (30)时间限制400 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, YueThis time let us consider
2015-08-25 18:06:03
1506
原创 05-图3. 六度空间 (30)
05-图3. 六度空间 (30)时间限制1500 ms内存限制65536 kB代码长度限制8000 B判题程序Standard“六度空间”理论又称作“六度分隔(Six Degrees of Separation)”理论。这个理论可以通俗地阐述为:“你和任何一个陌生人之间所
2015-07-26 16:58:39
1280
原创 05-图2. Saving James Bond - Easy Version (25)
05-图2. Saving James Bond - Easy Version (25)时间限制200 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, YueThis time let us consider
2015-07-26 00:21:01
1735
2
原创 05-图1. List Components (25)
05-图1. List Components (25)时间限制200 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, YueFor a given undirected graph with N vertic
2015-07-25 16:58:26
879
原创 04-树9. Path in a Heap (25)
04-树9. Path in a Heap (25)时间限制150 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, YueInsert a sequence of given numbers into an
2015-07-25 10:59:50
657
原创 04-树8. Complete Binary Search Tree (30)
04-树8. Complete Binary Search Tree (30)时间限制100 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, YueA Binary Search Tree (BST) is
2015-07-25 10:21:11
650
原创 04-树7. Search in a Binary Search Tree (25)
04-树7. Search in a Binary Search Tree (25)时间限制100 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, YueTo search a key in a binary
2015-07-25 09:43:26
735
原创 04-树6. Huffman Codes (30)
04-树6. Huffman Codes (30)时间限制200 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, YueIn 1953, David A. Huffman published his pape
2015-07-25 09:15:53
2840
1
原创 04-树5. File Transfer (25)
04-树5. File Transfer (25)时间限制150 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, YueWe have a network of computers and a list of
2015-07-22 22:29:37
1308
原创 04-树4. Root of AVL Tree (25)
04-树4. Root of AVL Tree (25)时间限制100 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, YueAn AVL tree is a self-balancing binary se
2015-07-22 20:34:51
1428
原创 03-树3. Tree Traversals Again (25)
03-树3. Tree Traversals Again (25)时间限制200 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, YueAn inorder binary tree traversal can
2015-07-22 09:58:11
2594
原创 03-树2. List Leaves (25)
03-树2. List Leaves (25)时间限制400 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, YueGiven a tree, you are supposed to list all the
2015-07-20 22:33:27
3187
原创 03-树1. 二分法求多项式单根(20)
03-树1. 二分法求多项式单根(20)时间限制400 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者杨起帆(浙江大学城市学院)二分法求函数根的原理为:如果连续函数f(x)在区间[a, b]的两个端点取值异号,即f(a
2015-07-20 21:09:10
471
原创 02-线性结构3. 求前缀表达式的值(25)
02-线性结构3. 求前缀表达式的值(25)时间限制400 ms内存限制65536 kB代码长度限制8000 B判题程序Standard算术表达式有前缀表示法、中缀表示法和后缀表示法等形式。前缀表达式指二元运算符位于两个运算数之前,例如2+3*(7-4)+8/4的前缀表达
2015-07-20 20:13:41
1039
原创 #29 Divide Two Integers
题目链接:https://leetcode.com/problems/divide-two-integers/Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.int divide(in
2015-07-19 22:53:41
551
原创 #28 Implement strStr()
题目链接:https://leetcode.com/problems/implement-strstr/Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Update
2015-07-19 19:31:57
409
原创 #27 Remove Element
题目链接:https://leetcode.com/problems/remove-element/Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed.
2015-07-19 17:13:21
642
原创 #26 Remove Duplicates from Sorted Array
题目链接:https://leetcode.com/problems/remove-duplicates-from-sorted-array/Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.
2015-07-19 17:04:28
577
原创 #25 Reverse Nodes in k-Group
题目链接:https://leetcode.com/problems/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
2015-07-19 16:53:09
502
原创 #24 Swap Nodes in Pairs
题目链接:https://leetcode.com/problems/swap-nodes-in-pairsGiven 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
2015-07-18 23:08:57
436
原创 #23 Merge k Sorted Lists
题目链接:https://leetcode.com/problems/merge-k-sorted-lists/Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity./** * Definition for singly-l
2015-07-18 23:03:45
548
原创 #22 Generate Parentheses
题目链接:https://leetcode.com/problems/generate-parentheses/Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a
2015-07-14 16:41:36
601
原创 #21 Merge Two Sorted Lists
题目链接:https://leetcode.com/problems/merge-two-sorted-lists/Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two
2015-07-14 14:57:50
601
原创 #20 Valid Parentheses
题目链接:https://leetcode.com/problems/valid-parentheses/Given a string containing just the characters '(', ')','{', '}', '[' and ']', determine if the input string is valid.The brackets m
2015-07-14 14:54:57
505
原创 #19 Remove Nth Node From End of List
题目链接:https://leetcode.com/problems/remove-nth-node-from-end-of-list/Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list:
2015-07-14 12:43:38
626
原创 #18 4Sum
题目链接:https://leetcode.com/problems/4sum/依次将问题转化为3Sum、2Sum问题, 后两个问题解法见关联博文。/** * Return an array of arrays of size *returnSize. * Note: The returned array must be malloced, assume caller calls fr
2015-07-14 11:39:51
685
原创 #17 Letter Combinations of a Phone Number
题目链接:https://leetcode.com/problems/letter-combinations-of-a-phone-number/Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to l
2015-07-14 08:30:32
651
原创 #16 3Sum Closest
题目链接:https://leetcode.com/problems/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 i
2015-06-22 16:52:23
627
原创 #15 3Sum
题目链接:https://leetcode.com/problems/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 o
2015-06-22 16:27:12
608
原创 #14 Longest Common Prefix
题目链接:https://leetcode.com/problems/longest-common-prefix/Write a function to find the longest common prefix string amongst an array of strings.char* longestCommonPrefix(char** strs, int
2015-06-21 21:50:02
443
原创 #13 Roman to Integer
题目链接:https://leetcode.com/problems/roman-to-integer/Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.int Digit(char ch) {
2015-06-21 21:22:28
411
原创 #12 Integer to Roman
题目链接:https://leetcode.com/problems/integer-to-roman/Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.char* intToRoman(int
2015-06-21 21:20:36
429
原创 #11 Container With Most Water
原题链接:https://leetcode.com/problems/container-with-most-water/Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are draw
2015-06-21 18:24:27
451
原创 #10 Regular Expression Match
题目链接:https://leetcode.com/problems/regular-expression-matching/Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more
2015-06-21 16:04:11
577
原创 #9 Palindrome Number
题目链接:https://leetcode.com/problems/palindrome-number/Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative inte
2015-06-21 13:48:11
567
原创 #8 String to Integer (atoi)
题目链接:https://leetcode.com/problems/string-to-integer-atoi/Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, ple
2015-06-21 13:31:10
544
原创 #7 Reverse Integer
题目链接:https://leetcode.com/problems/reverse-integer/Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thou
2015-06-21 13:29:01
355
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人