自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

Carol

leetcode notes专用

  • 博客(27)
  • 收藏
  • 关注

原创 二叉树

引自#include<iostream>using namespace std;//定义节点struct TreeNode{ char val; TreeNode *left; TreeNode *right; TreeNode(char x): val(x), left(NULL), right(NULL) {}};//按照前序顺序建立二...

2018-06-13 00:30:19 123

原创 leetcode-376-最长摆动序列

A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either pos...

2018-06-12 23:52:10 974

原创 leetcode-134-gas station

在一条环路上有 N 个加油站,其中第 i 个加油站有汽油 gas[i] 升。你有一辆油箱容量无限的的汽车,从第 i 个加油站开往第 i+1 个加油站需要消耗汽油 cost[i] 升。你从其中的一个加油站出发,开始时油箱为空。如果你可以绕环路行驶一周,则返回出发时加油站的编号,否则返回 -1。说明: 如果题目有解,该答案即为唯一答案。输入数组均为非空数组,且长度相同。输入数组中的元素均为非负数。示例...

2018-06-12 21:02:14 131

原创 leetcode-174. Dungeon Game

class Solution {public: int calculateMinimumHP(vector<vector<int>>& dungeon){ //正着看的话,只有局部最优,没有全局最优,类似于贪心 //应该倒着动态规划 int m = dungeon.size(); int n ...

2018-06-12 08:53:46 128

原创 leetcode-55-Jump Game

class Solution {public: bool canJump(vector<int>& nums) { int length = nums.size(); if(length == 1) return true; vector<int> global(length); //走到第i格的时候所能跳到...

2018-06-11 09:45:24 118

原创 leetcode-Tree-98. Validate Binary Search Tree(判断是否是二叉搜索树)

Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.The right ...

2018-05-24 15:08:10 115

原创 面试题汇总——数据结构部分(持续更新)

1.完全二叉树的性质面试题:如果一个完全二叉树的结点总数为768个,求叶子结点的个数。由二叉树的性质知:n0=n2+1,将之带入768=n0+n1+n2中得:768=n1+2n2+1,因为完全二叉树度为1的结点个数要么为0,要么为1,那么就把n1=0或者1都代入公式中,很容易发现n1=1才符合条件。所以算出来n2=383,所以叶子结点个数n0=n2+1=384。总结规律:如果一棵完全二叉树的结点总...

2018-05-24 11:40:40 331

原创 leetcode-Tree-94-Binary Tree Inorder Traversal(中序遍历)

94-中序遍历二叉树Given a binary tree, return the inorder traversal of its nodes' values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [1,3,2]/** * Definition for a binary tree node. * s...

2018-05-24 11:35:20 109

原创 leetcode-31-Next Permutation

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible ord...

2018-05-22 23:45:58 82

原创 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 minimizesthe sum of all numbers along its path.Note: You can only move either down or right at any ...

2018-05-22 23:11:46 76

原创 leetcode-26.Remove Duplicates from Sorted Array

Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this by modifying...

2018-05-22 23:00:59 69

原创 leetcode-24. Swap Nodes in Pairs

Given a linked list, swap every two adjacent nodes and return its head.Example:Given 1->2->3->4, you should return the list as 2->1->4->3.Note:Your algorithm should use only constant...

2018-05-22 19:33:54 69

原创 leetcode-23. Merge k Sorted Lists(优先队列priority_queue)

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input:[  1->4->5,  1->3->4,  2->6]Output: 1->1->2->3->4->4...

2018-05-22 18:19:18 469 1

原创 leetcode-21-Merge Two Sorted Lists && 88-Merge Sorted Array

Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, 1->3->4Output: 1->1...

2018-05-22 16:50:32 110

原创 leetcode-20-Valid Parentheses

class Solution {public: bool isValid(string s) { stack<char> paren; for (char& c : s) { switch (c) { case '(': case '{': ...

2018-05-22 15:50:51 63

原创 leetcode-19-Remove Nth Node From End of List

ont pass!!!Given a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the ...

2018-05-22 09:45:06 80

原创 leetcode-14-Longest Common Prefix

class Solution {public: string longestCommonPrefix(vector<string>& strs) { if(strs.empty()) return "";//注意特殊情况的判断 string ans=strs[0]; for(int i=1;i<strs.size(...

2018-05-22 00:36:43 82

原创 leetcode-12-Integer to Roman

Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D 5...

2018-05-22 00:10:02 71

原创 leetcode-11-Container With Most Water

Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two ...

2018-05-21 23:28:13 86

原创 leetcode-9-Palindrome Number

Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.Example 1:Input: 121Output: trueExample 2:Input: -121Output: falseExplanation: F...

2018-05-21 22:47:56 130

原创 leetcode-8-String to Integer (atoi)

Implement atoi which converts a string to an integer.The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this ...

2018-05-21 21:03:27 57

原创 leetcode-7-Reverse Integer

Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Note:Assume we are dealing with an envir...

2018-05-18 12:50:40 69

原创 leetcode-6-ZigZag Conversion

The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I I G...

2018-05-18 12:10:54 51

原创 leetcode-1-two sum

Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same el...

2018-05-18 09:01:08 122

原创 leetcode-5-Longest Palindromic Substring

Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: "babad"Output: "bab"Note: "aba" is also a valid answer.Example 2:...

2018-05-17 23:33:20 59

原创 leetcode-3-Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with the l...

2018-05-15 21:02:18 52

原创 leetcode-2-add two numbers

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i...

2018-05-15 10:59:34 90

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除