Leetcode题录
liushaofang
求知若渴、虚心若愚
展开
-
github上的leetcode题库App开发
源码地址为:https://github.com/fripSide/LeetCode-Android希望能与有识之士一起共同开发,请求加入开发组的可以QQ联系麻工(392167610)!!!原创 2016-02-20 16:03:37 · 9939 阅读 · 0 评论 -
Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example, S = “ADOBECODEBANC” T = “ABC” Minimum window is “BANC”.Note:原创 2016-05-15 22:28:29 · 327 阅读 · 0 评论 -
Trie树(字典树)的实现
Lintcode 442上实现Trie树 http://www.lintcode.com/zh-cn/problem/implement-trie/class TrieNode{public: TrieNode() { for(int i = 0; i < 26; i++) { children[i] = nullptr;原创 2017-11-28 18:47:28 · 234 阅读 · 0 评论 -
Rotate Image
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 means you have to modify the input 2D matrix direct原创 2017-12-10 22:32:41 · 373 阅读 · 0 评论 -
amazon phone interview
Reverse the word in a sentence. Like: input ”Hello world Amazon”, output “olleH dlrow nozamA”#include <string>#include <iostream>#include <cstdio>using namespace std;class Solution{public: stat原创 2017-12-21 18:11:02 · 399 阅读 · 0 评论 -
Combination Sum (lintcode 135)
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited number of t原创 2017-12-21 18:20:12 · 140 阅读 · 0 评论 -
全排列生成的迭代算法
Given a collection of distinct numbers, return all possible permutations.目前web上大多数解法都是递归解法,基于“所有的递归算法都存在对应的迭代算法”的基本原理,本文提出了一种迭代算法,通过online judge。class Solution {public: static vector<vector<int> >原创 2017-12-04 23:57:39 · 1556 阅读 · 0 评论 -
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 ele原创 2017-12-15 13:16:41 · 161 阅读 · 0 评论 -
Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5,7],原创 2017-12-05 19:15:14 · 286 阅读 · 0 评论 -
Reverse Linked List
Reverse a singly linked list./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solutio原创 2017-12-07 13:05:51 · 141 阅读 · 0 评论 -
Partition to K Equal Sum Subsets
Given an array of integers nums and a positive integer k, find whether it’s possible to divide this array into k non-empty subsets whose sums are all equal.Example 1: Input: nums = [4, 3, 2, 3, 5,原创 2018-01-12 18:32:59 · 237 阅读 · 0 评论 -
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原创 2018-01-09 01:06:57 · 270 阅读 · 0 评论 -
Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes’ values.For example: Given binary tree [1,null,2,3],1 \ 2 / 3return [3,2,1].Note: you do it iteratively....原创 2018-03-08 21:00:00 · 131 阅读 · 0 评论 -
168. Excel Sheet Column Title
输入一个数,计算该数对应的Microsoft Excel表中的列名称,示例:0->A 1–>B 25–>Z 26–>AA 27–>AZ 2626->ZA, 2726->AAAstring getExcelColumnName(int n) { string result = ""; int delta = 0; do { int r = ...原创 2019-04-13 15:51:14 · 171 阅读 · 0 评论 -
171. Excel Sheet Column Number
Given a column title as appear in an Excel sheet, return its corresponding column number.For example:A -> 1B -> 2C -> 3Z -> 26AA -> 27AB -> 28Example 1:Input: “A”Output: 1...原创 2019-04-13 16:11:51 · 97 阅读 · 0 评论 -
572. Subtree of Another Tree
Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this node...原创 2019-04-13 22:04:57 · 96 阅读 · 0 评论 -
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 le原创 2016-05-08 22:36:22 · 556 阅读 · 0 评论 -
Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note: Given m, n satisfy the following co原创 2016-04-20 21:26:07 · 453 阅读 · 0 评论 -
Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3.class Solution {public: Lis原创 2016-04-12 20:10:00 · 252 阅读 · 0 评论 -
Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguous subarray [4,−1,2,1] has the原创 2016-04-10 19:51:16 · 311 阅读 · 0 评论 -
Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.You原创 2016-04-29 23:41:37 · 313 阅读 · 0 评论 -
Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example, Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You may no原创 2016-04-30 12:12:14 · 243 阅读 · 0 评论 -
Remove Duplicates from Sorted List II
Remove Duplicates from Sorted List II原创 2016-04-17 23:46:14 · 301 阅读 · 0 评论 -
Quick Sort & Binary Merge Sort
class Solution{ //[start, end) void quicksort(vector<int> & arr, int start, int end){ if(end - start <= 1){ return; } int pivot = arr[start]; int i =原创 2016-05-01 20:44:27 · 666 阅读 · 0 评论 -
Sort List
Sort a linked list in O(n log n) time using constant space complexity.基于binary merge sort算法的思想实现。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; *原创 2016-05-02 19:34:23 · 249 阅读 · 0 评论 -
Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL./** * Definition for singly-linked list.原创 2016-05-02 21:38:09 · 279 阅读 · 0 评论 -
Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes’ values.For example, Given {1,2,3,4}, reorder it to {1,4,2,3}原创 2016-05-02 23:54:52 · 361 阅读 · 0 评论 -
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.Example: Given nums = [2, 7, 1原创 2016-05-03 08:37:00 · 282 阅读 · 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 farthest leaf node./** * Definition for a binary tree node.原创 2016-05-03 09:16:11 · 294 阅读 · 0 评论 -
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./** * Definition for a binary tree node.原创 2016-05-03 09:44:50 · 262 阅读 · 0 评论 -
Substring with Concatenation of All Words
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and wit原创 2016-05-15 16:29:37 · 441 阅读 · 0 评论 -
Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of the原创 2016-05-04 22:12:01 · 309 阅读 · 0 评论 -
Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linke原创 2016-05-04 23:08:00 · 414 阅读 · 0 评论 -
算法网站搜集
算法网站搜集IOI:http://olympiads.win.tue.nl/ioi/topcoder.com/tchttp://www.markwaymall.comhttps://www.hackerrank.com/http://www.codevs.cn/https://visualgo.nethttps://zh.visualgo.net/HackerRankusacoh...原创 2019-07-08 16:06:57 · 208 阅读 · 0 评论