摘要:
题目地址: https://leetcode.com/problems/maximum-subarray/description/ 题目描述: 经典的求最大连续子数组之和。 解法: 遍历这个vector,每次循环累加当前数值,同时更新最大值,若当前的累加和是负数,需要更新为0,因为在进行下一次累加求 阅读全文
摘要:
问题描述: php在给端提供接口,比如PC和安卓,ios等,如果返回json格式的数据,当返回数据的为数组,且key为字符串时,json化后将返回jsonObject,但是如果是空数组,有可能返回的就是jsonArray,数据结构不一致导致端解析json失败。 如: 输出: 但是如果是: 输出: 如 阅读全文
摘要:
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* r... 阅读全文
摘要:
class Solution { public: void reverseWords(string &s) { string result; int size = s.length(); int length = 0; for (int i = size - 1; i >= 0; i--) { ... 阅读全文
摘要:
class Solution { public: bool searchMatrix(vector>& matrix, int target) { int m = matrix.size(); if (!m) { return false; } int n = matrix.at(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... 阅读全文
摘要:
思路: 遍历矩阵,结合dfs解即可。 阅读全文
摘要:
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: 阅读全文
摘要:
class Solution { public: static bool canFinish(int numCourses, vector<pair<int, int>>& prerequisites) { //初始化入度 vector<int> indegree(numCourses, 0); / 阅读全文