
LeetCode
CV大白菜
这个作者很懒,什么都没留下…
展开
-
LeetCode 33. Search in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).You are given a target value to search. If found in t...原创 2018-11-15 17:54:42 · 101 阅读 · 0 评论 -
LeetCode 504. Base 7
Given an integer, return its base 7 string representation.(七进制)Example 1:Input: 100Output: “202”Example 2:Input: -7Output: “-10”class Solution {public: string convertToBase7(int num) { ...原创 2018-12-04 20:36:42 · 169 阅读 · 0 评论 -
LeetCode 79. Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically nei...原创 2018-11-23 14:28:25 · 121 阅读 · 0 评论 -
LeetCode 18. 4Sum
Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d= target? Find all unique quadruplets in the array which gives the sum of targ...原创 2018-11-20 11:55:55 · 114 阅读 · 0 评论 -
LeetCode 15. 3Sum
Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must not contain ...原创 2018-11-20 11:10:19 · 101 阅读 · 0 评论 -
LeetCode 74. Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each row is ...原创 2018-11-22 16:41:02 · 107 阅读 · 0 评论 -
LeetCode 16. 3Sum Closest
Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would ...原创 2018-11-19 17:52:26 · 125 阅读 · 0 评论 -
LeetCode 64. Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at any...原创 2018-11-19 17:13:05 · 94 阅读 · 0 评论 -
LeetCode 63. Unique Paths II
动态规划,不同于Unique Path的地方在于如果矩阵有元素为1,则为障碍,此时可以令通向该节点的路径数为0,同时需要注意,在矩阵出发位置的地方,即第一行和第一列,若这两个地方出现了‘1’,则该节点向右和向下的路都没有了,所以遍历第一行第一列,寻找可以出发的几个节点。class Solution {public: int uniquePathsWith...原创 2018-11-19 16:29:14 · 127 阅读 · 0 评论 -
59. Spiral Matrix II
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.Example:Input: 3Output:[[ 1, 2, 3 ],[ 8, 9, 4 ],[ 7, 6, 5 ]]旋转式写矩阵,最直观的方式就是一个边一个边的写矩阵。cl...原创 2018-11-19 14:42:26 · 116 阅读 · 0 评论 -
LeetCode 55. Jump Game
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 maximum jump length at that position.Determine if you ar...原创 2018-11-19 10:21:49 · 127 阅读 · 0 评论 -
LeetCode 81. Search in Rotated Sorted Array II
class Solution {public: bool search(vector<int>& nums, int target) { int left = 0, right = nums.size() - 1,mid; while (left <= right) { mid = (right + left...原创 2018-11-15 22:19:25 · 114 阅读 · 0 评论 -
LeetCode 769. Max Chunks To Make Sorted
class Solution {public: int maxChunksToSorted(vector<int>& arr) { int mx=0,res=0; for(int i=0;i<arr.size();i++){ mx=max(arr[i],mx); if(mx==i)...原创 2018-11-15 20:30:09 · 128 阅读 · 0 评论 -
LeetCode 507. Perfect Number
We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself.Now, given an integer n, write a function that returns true when it is a perfect...原创 2018-12-05 10:38:07 · 150 阅读 · 0 评论