- 博客(78)
- 收藏
- 关注
转载 廖雪峰GIT课程笔记
1. git 简介1. Git是目前最先进的分布式版本控制系统。2. 创建版本库:cd到目录下 -> git init3. 把一个文件添加到git仓库需要两部:git add <filename> --> git commit -m <commit message> git add 分多次添加-->git commit 一次性提交...
2018-06-26 17:06:00 179
转载 C语言指针、数组和函数的一些总结
主要来自于孟宪福老师的分布式对象课程。int a[7][8];// a指向 a-->a[0]-->a[0][0] a[0]是第0行一维数组// a + i --> a[i] --> a[i][0]a[i][j];// 等价于*( *(p + i ) + j)定义一个函数返回7*8的数组aint ( *f ...
2018-06-10 10:59:00 259
转载 廖雪峰python课程笔记
1. 可以通过 print(os.sys.path) 来查看python可导入的包的路径情况,这会打印出一个list。当我们import某一个包时,python会根据这个list,从前向后搜寻相匹配的包来导入。当然我们也可以通过修改这个list来改变python要导入的包,既可以append也可以修改某一维的值。2. 我们也可以通过在site-packages路径下添加.pth文件来...
2017-12-26 16:32:00 177
转载 输出二叉树中和最大的路径
// root指向根节点,curSum记录当前路径的和,path记录当前的路径的值,max_path记录全局最大的路径,max记录全局最大的路径和。// 在到达叶节点并且当前路径和大于max时用path更新max_pathvoid GetMaxSumPath(TreeNode * root, int curSum, vector<int> & ...
2017-10-10 21:41:00 503
转载 剑指offer - 面试题33 - 把数组排成最小的数
#include<iostream>#include<vector>#include<string>#include<strstream>#include<algorithm>bool compare(const string & num1, const string & num2){...
2017-10-05 20:30:00 88
转载 归并排序C++实现及求逆序对的个数
1.归并排序的递归实现:#include<iostream>#include<vector>#include<string>#include<strstream>#include<algorithm>#include<unordered_map>using namespace std;...
2017-10-03 19:37:00 749
转载 LeetCode83 - Remove Duplicates from Sorted List--删除有序链表中重复的元素
思路:使用两个指针p1和p2遍历链表,p1在前p2在后。若p1指向的值小于p2指向的值,则p2向前走,直到二者不相等,然后更改p1的指针,再将p1和p2都向前走一步,这么做直到p2到达链表尾部。/** * Definition for singly-linked list. * struct ListNode { * int val; * Li...
2017-10-02 13:04:00 64
转载 LeetCode35 - Search Insert Position--二分查找,若不存在则返回应插入的位置
class Solution {public: int searchInsert(vector<int>& nums, int target) { int len=nums.size(); if(len < 1) return 0; int low=0,high...
2017-10-02 11:17:00 173
转载 LeetCode120 - Triangle
题目描述:思路1:利用动态规划。由于空间复杂度的限制,直接在triangle数组上进行修改,即把triangle数组当作dp数组。当j == 0时(即每一行的第一个元素),triangle[i][j] += triangle[i - 1][j];当j == col - 1时(即每一行的最后一个元素),triangle[i][j] += triangle[i - 1][j - ...
2017-09-28 15:24:00 126
转载 LeetCode53 - Maximum Subarray:求数组的连续子数组的最大和,并记录子数组的起点和终点位置...
思路:《剑指offer》上有这一道题的详解,利用动态规划的思想。class Solution {public: int maxSubArray(vector<int>& nums) { int len=nums.size(); int max_ending_here=nums[0]; ...
2017-09-26 14:31:00 133
转载 给定一个升序数组,求数组中绝对值不相同的元素的个数
题目描述:给定一个整形数组,数组是升序排列的,可能存在负数,统计数组中所有不同绝对值的元素的个数。思路:设置两个指针,分别指向数组的第一个元素和最后一个元素,可以看做是两个有序数组的合并过程(从大到小合并)。#include<iostream>#include<vector>using namespace std;int GetNumber...
2017-09-26 10:46:00 368
转载 LeetCode4 - median of two sorted arrays--求两个有序数组的中位数
class Solution {public: double FindKthNumber(vector<int> numbers1, vector<int>numbers2, int len1, int len2, int start1, int start2, int k) { if (len1 &g...
2017-09-24 21:55:00 75
转载 堆排序 C++实现
#include<iostream>#include<vector>#include<stack>#include<algorithm>#include<string>#include<set>#include <functional>using namespace std...
2017-09-19 16:28:00 98
转载 链表的冒泡排序-没有头结点,交换链表节点
问题描述:对一个没有头结点的链表进行冒泡排序,如果出现逆序交换链表的节点,而不是交换链表的值。#include<iostream>#include<vector>#include<map>#include<string>using namespace std;struct ListNode{ i...
2017-08-28 17:44:00 413
转载 Linux常用命令总结
1. 查看并修改文件权限(1)查看文件详细信息,包括权限命令:ls -l第一个字符表示文件类型:d代表目录,-代表非目录。接下来的9个字符每三个为一组,分别表示文件所有者的权限、同组用户的权限以及其它用户的权限。r表示拥有读权限,w表示拥有写权限,x表示拥有执行权限,-表示没有该权限。接下来的一个数字表示引用计数。接下来的两个名称分别是文件所有者以及...
2017-08-06 11:26:00 83
转载 53. leetcode557. Reverse Words in a String III
557. Reverse Words in a String IIIGiven a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order....
2017-04-13 22:03:00 85
转载 LeetCode96 - Unique Binary Search Trees--卡特兰数的应用,不同二叉树的个数
96. Unique Binary Search TreesGivenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 uniqueBST's. ...
2017-04-09 22:04:00 80
转载 51. leetcode 530. Minimum Absolute Difference in BST
530. Minimum Absolute Difference in BSTGiven a binary search tree with non-negative values, find the minimumabsolute differencebetween values of any two nodes.Example:Input: 1...
2017-04-09 22:03:00 98
转载 50. leetcode 520. Detect Capital
520. Detect CapitalGiven a word, you need to judge whether the usage of capitals in it is right or not.We define the usage of capitals in a word to be right when one of the following cases ho...
2017-04-09 22:02:00 100
转载 48. leetcode 105题 由树的前序序列和中序序列构建树结构
leetcode 105题,由树的前序序列和中序序列构建树结构。详细解答参考《剑指offer》page56.先序遍历结果的第一个节点为根节点,在中序遍历结果中找到根节点的位置。然后就可以将问题拆分,递归求解。/** * Definition for a binary tree node. * struct TreeNode { * int val; *...
2017-04-09 22:01:00 69
转载 LeetCode94 - Binary Tree Inorder Traversal--二叉树的递归和非递归中序遍历
递归方法:非递归:要借助栈,可以利用C++ STL中的stack。首先将根节点压栈,然后压入栈顶元素的左节点直到叶子节点,然后访问叶子节点后压入该节点的右子节点。/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *lef...
2017-04-09 22:01:00 74
转载 47. leetcode 437. Path Sum III
437. Path Sum IIIYou are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does not need to start or end at the ro...
2017-04-09 22:00:00 97
转载 46. leetcode 500. Keyboard Row
500. Keyboard RowGiven a List of words, return the words that can be typed using letters ofalphabeton only one row's of American keyboard like the image below.Example 1:Input: [...
2017-04-09 21:59:00 87
转载 45. leetcode 504. Base 7
504. Base 7Given an integer, return its base 7 string representation.Example 1:Input: 100Output: "202"Example 2:Input: -7Output: "-10"Note:The input will be in range of [...
2017-04-09 21:58:00 112
转载 LeetCode28 - Implement strStr():字符串的匹配
28. Implement strStr()Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.思路:子串匹配,朴素匹配。复杂度O(n2)。每次子串和模式串匹配失配时,子串的指针都回...
2017-04-09 21:56:00 92
转载 43. leetcode 459. Repeated Substring Pattern
459. Repeated Substring PatternGiven a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the gi...
2017-04-09 21:55:00 76
转载 LeetCode70 - Climbing Stairs--爬楼梯,斐波那契数列
70. Climbing StairsYou are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note:...
2017-04-09 21:55:00 101
转载 41. leetcode 53. Maximum Subarray
53. Maximum SubarrayFind the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[-2,1,-3,4,-1,2,1,-5,4],the contiguo...
2017-04-09 21:54:00 89
转载 39. leetcode 326. Power of Three
326. Power of ThreeGiven an integer, write a function to determine if it is a power of three.Follow up:Could you do it without using any loop / recursion?思路:看这个数取以...
2017-04-09 21:53:00 90
转载 40. leetcode 202. Happy Number
Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squa...
2017-04-09 21:53:00 58
转载 38. leetcode 405. Convert a Number to Hexadecimal
405. Convert a Number to HexadecimalGiven an integer, write an algorithm to convert it to hexadecimal. For negative integer,two’s complementmethod is used.Note:All letters in hexadec...
2017-04-09 21:52:00 66
转载 37. leetcode 108. Convert Sorted Array to Binary Search Tree
108. Convert Sorted Array to Binary Search Tree思路:利用一个有序数组构建一个平衡二叉排序树。直接递归构建,取中间的元素为根节点,然后分别构建左子树和右子树。转载于:https://www.cnblogs.com/vincent93/p/6686631.html...
2017-04-09 21:51:00 60
转载 LeetCode415 - Add Strings 用字符串模拟整数相加
415. Add StringsGiven two non-negative integersnum1andnum2represented as string, return the sum ofnum1andnum2.Note:The length of bothnum1andnum2is < 5100.Bothnum1and...
2017-04-09 21:51:00 54
转载 35. leetcode 501. Find Mode in Binary Search Tree
501. Find Mode in Binary Search TreeGiven a binary search tree (BST) with duplicates, find all themode(s)(the most frequently occurred element) in the given BST.Assume a BST is defined a...
2017-04-09 21:50:00 61
转载 33. leetcode 268. Missing Number
Given an array containingndistinct numbers taken from0, 1, 2, ..., n, find the one that is missing from the array.For example,Givennums=[0, 1, 3]return2.Note:Your algorithm should...
2017-04-09 21:49:00 58
转载 34. leetcode 447. Number of Boomerangs
Givennpoints in the plane that are all pairwise distinct, a "boomerang" is a tuple of points(i, j, k)such that the distance betweeniandjequals the distance betweeniandk(the order of th...
2017-04-09 21:49:00 57
转载 32.将一个单向链表反转
思路一:递归思路二:迭代从头至尾,依次反转相邻节点指针转载于:https://www.cnblogs.com/vincent93/p/6686610.html
2017-04-09 21:48:00 49
转载 31. leetcode 122. Best Time to Buy and Sell Stock II
122. Best Time to Buy and Sell Stock IISay you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may comple...
2017-04-09 21:47:00 53
转载 30. leetcode 121. Best Time to Buy and Sell Stock
121. Best Time to Buy and Sell StockSay you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (i...
2017-04-09 21:47:00 45
转载 29. leetcode 167. Two Sum II - Input array is sorted
167. Two Sum II - Input array is sortedGiven an array of integers that is alreadysorted in ascending order, find two numbers such that they add up to a specific target number.The function t...
2017-04-09 21:46:00 47
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人