
LeetCode
IMISSHOT
不取于相,如如不动
展开
-
Add Two Numbers
今天开始刷LeedCode了.发现智商不够用了.有些解题方法是Goole来的...答题语言都是c语言,顺便也是巩固了一下数据结构原题链接:点击打开链接/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }原创 2017-10-07 15:46:21 · 191 阅读 · 0 评论 -
Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example: Given the below binary tree and sum原创 2018-01-18 13:21:32 · 191 阅读 · 0 评论 -
<T110>Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ原创 2018-01-18 14:38:09 · 203 阅读 · 0 评论 -
Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the原创 2018-01-18 15:26:37 · 206 阅读 · 0 评论 -
Binary Tree Level Order Traversal
Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).For example: Given binary tree [3,9,20,null,null,15,原创 2018-01-18 21:49:56 · 254 阅读 · 0 评论 -
110. Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ原创 2018-01-18 22:22:16 · 202 阅读 · 0 评论 -
113. Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.For example: Given the below binary tree and sum = 22,return 给一个二叉树和一个数字sum,让你找出所有路径和为su原创 2018-01-18 22:46:35 · 303 阅读 · 0 评论 -
122. Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one原创 2018-01-18 23:16:21 · 217 阅读 · 0 评论 -
141. Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space?判断一个链表是否有环。条件是能否用O(1)的空间复杂度解决这个问题。既然不让我们用多余的空间,那么我们首先想到的是遍历这个链表,我们维持两个指针,一个快,一个慢,如果有环的原创 2018-01-18 23:38:09 · 217 阅读 · 0 评论 -
<T111> Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.这道题的目的就是求二叉树的最小高度. 和求二叉树高度不同的是,它需要判断每原创 2018-01-18 13:04:00 · 240 阅读 · 0 评论 -
<T121>Best Time To Buy And Sell Stack I
say you have an array for witch the i th element is the price of a given stock on day i. if you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),原创 2018-01-17 12:49:45 · 316 阅读 · 0 评论 -
<T125>Valid Palindrome
Given a string, determine if it is a palindrome. considering only alphanumeric characters and ignoring cases.Notes: Have you consider the string might be empty?class Solution{ bool isPalind原创 2018-01-16 21:32:51 · 235 阅读 · 0 评论 -
Remove Element
/*2017.10.7LeetCode : Remove Element 把数组中和val相等的值覆盖掉就行了.*/int removeElement(int* nums, int numsSize, int val) { int i, k = 0; for(i = 0; i < numsSize; i++){ if(nums[i] != val原创 2017-10-07 16:29:11 · 261 阅读 · 0 评论 -
RemoveDuplicates form Sort Array
/*2017.10.7LeetCode : RemoveDuplicates form Sort Array*/int removeDuplicates(int* nums, int numsSize) { int k = 0, i; if (numsSize == 0) return numsSize; for(i = 1; i < nu原创 2017-10-07 16:47:20 · 292 阅读 · 0 评论 -
Remove Duplicates from Sorted Array II
/*2017.10.7//LeedCode : Remove Duplicates from Sorted Array II 需要一个计数器,如果重复次数小于2,就把这个元素放到新数组里.*/int removeDuplicates(int* nums, int numsSize) { int k = 0, i, cnt = 1;; if(numsSize ==原创 2017-10-07 17:07:46 · 217 阅读 · 0 评论 -
plusone
/*2017.10.8LeedCode:plusone开始学c++了*/class Solution {public: vector plusOne(vector& digits) { vector ret(digits.size(), 0); int one = 1; for(int i = digits.size()-1; i原创 2017-10-08 10:05:38 · 278 阅读 · 0 评论 -
我对KMP算法的理解
我对KMP算法的理解翻译自: jBoxer's blog 原文链接: http://jakeboxer.com/blog/2009/12/13/the-knuth-morris-pratt-algorithm-in-my-own-words/ 在过去的几天,我读了好几篇关于“利用KMP算法查找字符串的解释”的文章。出于某些原因,没有一篇是能令我接受和理解的。每当翻译 2017-10-30 12:27:26 · 429 阅读 · 0 评论 -
Symmetric Tree
Given a binary tree, check whether it is a mirror of itself. For example, the binary tree[1,2,2,3,4,4,3] is a symmetric tree. Notes bonus points if you could solve it both recursively and iterat原创 2018-01-15 23:53:35 · 209 阅读 · 0 评论 -
Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the fastest leaf node. /*struct TreeNode{ int val;原创 2018-01-16 00:01:42 · 194 阅读 · 0 评论 -
Single Number
Given an array of integers, every element appears twice except for one. find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra原创 2018-01-16 13:04:53 · 198 阅读 · 0 评论 -
A+B problem
leetcode 开始收费了,开始转战lintcode。Write a function that add two numbers A and B. You should not use + or any arithmetic operators. ClarificationAre a and b both 32-bit integers?Yes.Can I use bit原创 2018-01-19 10:52:32 · 362 阅读 · 0 评论