摘要: 给定一个仅包含大小写字母和空格 ' ' 的字符串,返回其最后一个单词的长度。 如果不存在最后一个单词,请返回 0 。 说明:一个单词是指由字母组成,但不包含任何空格的字符串。 思路:丑陋但是pass了的代码,从后面判断,是否到达头部,或者下一个字符为空格符。 阅读全文
posted @ 2019-03-19 21:06 zzas12345 阅读(111) 评论(0) 推荐(0) 编辑
摘要: 给定一个非负整数数组,你最初位于数组的第一个位置。 数组中的每个元素代表你在该位置可以跳跃的最大长度。 判断你是否能够到达最后一个位置。 思路:dp,用一个数组表示当前位置能够到的最大位置,如果前一个位置能够达到下一个位置才开始起跳。注意【0】这个特殊情况,注意等于号; class Solution 阅读全文
posted @ 2019-03-19 17:26 zzas12345 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 给定一个包含 m x n 个元素的矩阵(m 行, n 列),请按照顺时针螺旋顺序,返回矩阵中的所有元素。 示例 1: 思路:愉快的旋转吧,硬着头皮来,一行一行地转动。 class Solution {public: vector<int> spiralOrder(vector<vector<int> 阅读全文
posted @ 2019-03-19 16:52 zzas12345 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。 示例: 思路:如果前面的数之和加起来不为零,则就有还有机会取一个最大值。否则cursum清零,等于下一个起始位的值。 给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一 阅读全文
posted @ 2019-03-19 16:11 zzas12345 阅读(243) 评论(0) 推荐(0) 编辑
摘要: Implement pow(x, n), which calculates x raised to the power n (xn). Example 1: Input: 2.00000, 10 Output: 1024.00000 Example 2: Input: 2.10000, 3 Outp 阅读全文
posted @ 2019-03-19 15:30 zzas12345 阅读(125) 评论(0) 推荐(0) 编辑
摘要: Given an array of strings, group anagrams together. Example: 阅读全文
posted @ 2019-03-19 15:07 zzas12345 阅读(216) 评论(0) 推荐(0) 编辑
摘要: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note: You have to rotate the image in-place, which 阅读全文
posted @ 2019-03-19 14:45 zzas12345 阅读(179) 评论(0) 推荐(0) 编辑
摘要: Given a collection of numbers that might contain duplicates, return all possible unique permutations. Example: 阅读全文
posted @ 2019-03-19 12:29 zzas12345 阅读(183) 评论(0) 推荐(0) 编辑
摘要: Given a collection of distinct integers, return all possible permutations. Example: 阅读全文
posted @ 2019-03-19 11:06 zzas12345 阅读(140) 评论(0) 推荐(0) 编辑