随笔分类 - 闲来无事
摘要:Given a linked list, rotate the list to the right by k places, where k is non-negative. Example 1: Example 2: 题意 把链表循环右移k个 题解 1 class Solution { 2 pub
阅读全文
摘要:The set [1,2,3,...,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, we get the following seque
阅读全文
摘要:Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. Example: 1 class Solution { 2 public: 3 vector
阅读全文
摘要:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word
阅读全文
摘要:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initia
阅读全文
摘要:Given a collection of intervals, merge all overlapping intervals. Example 1: Example 2: 题意 合并重合的闭区间 题解 1 bool operator <(const Interval& a, const Inte
阅读全文
摘要:Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maxim
阅读全文
摘要:Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. Example 1: Example 2: 题意 顺时针螺旋输出数组 题解 1 class
阅读全文
摘要:Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Example: Foll
阅读全文
摘要:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return the
阅读全文
摘要:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all
阅读全文
摘要:Implement pow(x, n), which calculates x raised to the power n (xn). Example 1: Example 2: Example 3: Note: -100.0 < x < 100.0 n is a 32-bit signed int
阅读全文
摘要:Given an array of strings, group anagrams together. Example: 题意 把由相同字母出现相同次数组成的字符串归到一起(数据可能重复) 题解 一开始我当成了任何一种字母只会出现一次做了,用的是long型作二进制用,自然WA了,其实后来可以用字符串
阅读全文
摘要: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
阅读全文
摘要:Given a collection of numbers that might contain duplicates, return all possible unique permutations. Example: 1 class Solution { 2 public: 3 vector<v
阅读全文
摘要:Given a collection of distinct integers, return all possible permutations. Example: 1 class Solution { 2 public: 3 void build(vector<bool>visited, vec
阅读全文
摘要:Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maxim
阅读全文
摘要:Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*'. The matching should cover the entire in
阅读全文
摘要:Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string. Example 1: Ex
阅读全文
摘要:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
阅读全文