摘要: 题目地址: https://leetcode.com/problems/maximum-subarray/description/ 题目描述: 经典的求最大连续子数组之和。 解法: 遍历这个vector,每次循环累加当前数值,同时更新最大值,若当前的累加和是负数,需要更新为0,因为在进行下一次累加求 阅读全文
posted @ 2018-04-20 15:23 南岛的森林 阅读(97) 评论(0) 推荐(0) 编辑
摘要: 问题描述: php在给端提供接口,比如PC和安卓,ios等,如果返回json格式的数据,当返回数据的为数组,且key为字符串时,json化后将返回jsonObject,但是如果是空数组,有可能返回的就是jsonArray,数据结构不一致导致端解析json失败。 如: 输出: 但是如果是: 输出: 如 阅读全文
posted @ 2018-01-30 19:43 南岛的森林 阅读(4587) 评论(0) 推荐(0) 编辑
摘要: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* r... 阅读全文
posted @ 2017-07-24 12:28 南岛的森林 阅读(103) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: void reverseWords(string &s) { string result; int size = s.length(); int length = 0; for (int i = size - 1; i >= 0; i--) { ... 阅读全文
posted @ 2017-07-21 11:13 南岛的森林 阅读(100) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: bool searchMatrix(vector>& matrix, int target) { int m = matrix.size(); if (!m) { return false; } int n = matrix.at(0)... 阅读全文
posted @ 2017-07-20 14:25 南岛的森林 阅读(109) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: string reverseWords(string s) { string temp; string ret; for (int i = 0; i 0) { reverse(temp.begin(), temp.end()); ret += temp; } return re... 阅读全文
posted @ 2017-06-06 12:29 南岛的森林 阅读(167) 评论(0) 推荐(0) 编辑
摘要: 思路: 遍历矩阵,结合dfs解即可。 阅读全文
posted @ 2017-05-31 21:39 南岛的森林 阅读(158) 评论(0) 推荐(0) 编辑
摘要: Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell. The distance between two adjacent cells is 1. Example 1: Input: 阅读全文
posted @ 2017-04-23 21:57 南岛的森林 阅读(300) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: static bool canFinish(int numCourses, vector<pair<int, int>>& prerequisites) { //初始化入度 vector<int> indegree(numCourses, 0); / 阅读全文
posted @ 2017-04-20 21:13 南岛的森林 阅读(113) 评论(0) 推荐(0) 编辑
摘要: 将 I am Beijing. 倒序为Beijing. like I 用栈实现: 1 #include <iostream> 2 #include <stack> 3 #include <string> 4 using namespace std; 5 int main() 6 { 7 string 阅读全文
posted @ 2017-04-02 12:40 南岛的森林 阅读(180) 评论(0) 推荐(0) 编辑