
leetcode
leetcode
HenryTien
爱编程、爱科技、爱生活、爱自己
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Bidirectional BFS双向BFS
from collections import deque class Solution: def doubleBFS(start,end): if start == end: return 1 # 分别从起点和终点开始的两个队列 startQueue,endQueue = deque()...原创 2020-01-06 22:48:40 · 380 阅读 · 0 评论 -
69. Binary Tree Level Order Traversal
/** * Definition of TreeNode: * class TreeNode { * public: * int val; * TreeNode *left, *right; * TreeNode(int val) { * this->val = val; * this->left = this-&...原创 2020-01-06 17:05:32 · 170 阅读 · 0 评论 -
LintCode 137. 克隆图
克隆图 中文English 克隆一张无向图. 无向图的每个节点包含一个 label 和一个列表 neighbors. 保证每个节点的 label 互不相同. 你的程序需要返回一个经过深度拷贝的新图. 新图和原图具有同样的结构, 并且对新图的任何改动不会对原图造成任何影响. Example 样例1 输入: {1,2,4#2,1,4#4,1,2} 输出: {1,2,4#2,1,4#4,1,2} 解...原创 2020-01-06 10:02:19 · 156 阅读 · 0 评论 -
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 ...原创 2020-01-05 00:21:55 · 105 阅读 · 0 评论 -
leetcode 27. Remove Element
Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory.原创 2017-10-26 16:37:31 · 236 阅读 · 0 评论 -
Leetcode 290. Word Pattern
Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.原创 2017-04-20 16:24:51 · 273 阅读 · 0 评论 -
leetcode 151. Reverse Words in a String
Given an input string, reverse the string word by word. For example, Given s = "the sky is blue", return "blue is sky the". Update (2015-02-12): For C programmers: Try to solve it in-place in原创 2017-04-17 11:57:23 · 316 阅读 · 0 评论 -
leetcode 155. Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() --原创 2017-04-16 07:38:29 · 227 阅读 · 0 评论 -
leetcode 217. Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element原创 2017-04-18 16:04:31 · 245 阅读 · 0 评论 -
leetcode 8. String to Integer (atoi)
Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca原创 2017-04-18 11:24:29 · 270 阅读 · 0 评论 -
leetcode 28. Implement strStr() 实现strStr()函数
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. class Solution { public: int strStr(string haystack, string need原创 2017-04-12 16:24:57 · 249 阅读 · 0 评论 -
leetcode 378. Kth Smallest Element in a Sorted Matrix
Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix. Note that it is the kth smallest element in the sorted order, not原创 2017-03-30 18:33:57 · 246 阅读 · 0 评论 -
leetcode 341. Flatten Nested List Iterator
题目在这class NestedIterator { public: NestedIterator(vector<NestedInteger> &nestedList) { for(int i=nestedList.size()-1;i>=0;--i){ s.push(nestedList[i]); } } int nex原创 2017-01-25 14:34:06 · 195 阅读 · 0 评论 -
LeetCode 258. Add Digits 题解
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, r原创 2017-01-16 20:37:56 · 249 阅读 · 0 评论 -
leetcode-389. Find the Difference
2017年1月2日 https://leetcode.com/problems/find-the-difference/class Solution { public: char findTheDifference(string s, string t) { for(int i=1;i<s.size();i++) {原创 2017-01-02 15:23:16 · 245 阅读 · 0 评论 -
leetcode 350. Intersection of Two Arrays II
https://leetcode.com/problems/intersection-of-two-arrays-ii/妈蛋,我还是个弱鸡,这样的题目也不能解决,~~(>_<)~~,算了自己不正确的思路,就不写了 既然他们是有序的,当然在此之前是给她排序哈.sort(nums1.begin(),nums1.end()); sort(nums1.begin(),nums1.end());然后确定长度原创 2017-01-03 09:02:31 · 260 阅读 · 0 评论 -
leetcode 随机概率 水塘抽样
https://leetcode.com/problems/linked-list-random-node//** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {原创 2017-01-23 21:54:54 · 832 阅读 · 0 评论 -
leetcode 141. Linked List Cycle
Given a linked list, determine if it has a cycle in it. /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next原创 2017-02-03 16:10:46 · 224 阅读 · 0 评论