![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leedcode
小脑袋真灵
世上无难事,就怕你太懒
展开
-
有一个长为n的数组A,求满足0≤a≤b<n的A[b]-A[a]的最大值。 给定数组A及它的大小n,请返回最大差值。 测试样例: [10,5],2 返回:0
算法思想:遍历一遍数组,每次遍历判断最小值,并计算是否是最大距离class LongestDistance {public: int getDis(vector A, int n) { // write code here int minValue = A[0]; int max = 0; for(int原创 2017-03-18 22:53:09 · 3683 阅读 · 1 评论 -
Given a binary tree, return the postorder traversal of its nodes' values.
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */cla原创 2017-03-17 14:21:42 · 427 阅读 · 0 评论 -
Sort a linked list using insertion sort
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *//*void insertionSort(int *a,int原创 2017-03-17 01:45:25 · 246 阅读 · 0 评论 -
Sort a linked list in O(n log n) time using constant space complexity.
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public:原创 2017-03-17 00:14:50 · 241 阅读 · 0 评论 -
简单错误记录
开发一个简单错误记录功能小模块,能够记录出错的代码所在的文件名称和行号。 处理:1.记录最多8条错误记录,对相同的错误记录(即文件名称和行号完全匹配)只记录一条,错误计数增加;(文件所在的目录不同,文件名和行号相同也要合并)2.超过16个字符的文件名称,只记录文件的最后有效16个字符;(如果文件名不同,而只是文件名的后16个字符和行号相同,也不要合并)3.输入的文件可能带路径,记录原创 2017-04-01 14:17:58 · 323 阅读 · 0 评论 -
leedcode word break
Given a string s and a dictionary of words dict, determine ifs can be segmented into a space-separated sequence of one or more dictionary words.For example, givens ="leetcode",dict =["leet", "原创 2017-03-21 11:49:55 · 255 阅读 · 0 评论 -
【LeetCode】Candy
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 must have at least原创 2017-03-19 18:04:20 · 190 阅读 · 0 评论 -
[leetcode] 134. Gas Station
There are N gas stations along a circular route, where the amount of gas at stationi isgas[i]. You have a car with an unlimited gas tank and it costscost[i]of gas to travel from stationi to its原创 2017-03-19 16:00:05 · 183 阅读 · 0 评论 -
在4x4的棋盘上摆满了黑白棋子,黑白两色的位置和数目随机其中左上角坐标为(1,1),右下角坐标为(4,4),现在依次有一些翻转操作,要对一些给定支点坐标为中心的上下左右四个棋子的颜色进行翻转,请计算出
在4x4的棋盘上摆满了黑白棋子,黑白两色的位置和数目随机其中左上角坐标为(1,1),右下角坐标为(4,4),现在依次有一些翻转操作,要对一些给定支点坐标为中心的上下左右四个棋子的颜色进行翻转,请计算出翻转后的棋盘颜色。给定两个数组A和f,分别为初始棋盘和翻转位置。其中翻转位置共有3个。请返回翻转后的棋盘。测试样例:[[0,0,1,1],[1,0,1,0],[0,1,1,0],[0,0,原创 2017-03-18 23:33:13 · 4476 阅读 · 0 评论 -
Given a binary tree, return the preorder traversal of its nodes' values.
vector tree::preorderTree(treeNode *root){ vector result; stack tempStack; treeNode *dummyRootNode = root;//不知道root值是否会被改变 所以用这种方式 要测试一下 if(dummyRootNode) tempStack.push原创 2017-03-17 14:27:14 · 784 阅读 · 0 评论