leetcode

Learn about leetcode, we have the largest and most updated leetcode information on alibabacloud.com

Leetcode removing duplicates from a sorted array

The recent study is quite boring, and very uninteresting, every day wasted a lot of time, such as this afternoon, is to make a hand idiom solitaire, I am also drunk ...And I don't know what to learn, so I decided to brush the questionAlthough I am the base of 0 algorithm, 0 logic ability Slag slag, but try to do a problem every day, always slowly progress Given array nums = [1,1,2],The function should return a new length of 2, and the first two elements of the original array nums are mo

Leetcode python 010

Tag: SPL for part return expression BSP nbsp Long []#实现正则表达式匹配并支持 '. ' and ' * '.# ' matches any single character.# ' * ' matches 0 or more of the preceding elements.#匹配应覆盖整个输入字符串 (non-partial).# #Some Examples:# #isMatch ("AA", "a") →false# #isMatch ("AA", "AA") →true# #isMatch ("AAA", "AA") →false# #isMatch ("AA", "A *") →true# #isMatch ("AA", ". *") →true# #isMatch ("AB", ". *") →true# #isMatch ("AaB", "C*a*b") →truedef ismatch (s,re):L=[]for k in range (Len (re)):If re[k]== ' * ':L.append (k

[Leetcode] [JavaScript] Reverse Linked List

Reverse Linked ListReverse a singly linked list.Click to show more hints.Hint:A linked list can be reversed either iteratively or recursively. Could you implement both?https://leetcode.com/problems/reverse-linked-list/ Reverses the linked list.1 /**2 * Definition for singly-linked list.3 * Function ListNode (val) {4 * This.val = val;5 * this.next = null;6 * }7 */8 /**9 * @param {listnode} headTen * @return {ListNode} One */ A varReverselist =function(head) { - if(!head | |!Head.next

[Leetcode] [JavaScript] Contains Duplicate II

Contains Duplicate IIGiven an array of integers and a integer k, return True if and only if there is, distinct indices i and j in the ARRA Y such that nums[i] = Nums[j] and the difference between I and J are at most K.https://leetcode.com/problems/contains-duplicate-ii/ 1 /**2 * @param {number[]} nums3 * @param {number} K4 * @return {Boolean}5 */6 varContainsnearbyduplicate =function(Nums, k) {7 varMap = {};8 for(varIinchnums) {9 if(Map[nums[i]]!==undefined) {Ten

Leetcode "4". Median of the different methods for Sorted Arrays--java

algorithm, shrinking the range of two arrays, and also changing the value of K relative to the upper starting point of the two search interval public double find (int[] A, int astart, int aend, int[] B, int bstart, I NT Bend,int kth) {//1. Unify the short length placed in the previous item of the find function parameter if (aend>bend) return find (B, bstart, bEnd, a, a Start, Aend, KTH); 2. Short length is empty, then the answer is equivalent to finding the median of anoth

[Leetcode] Kth largest Element in an array of K-large numbers

Find the kth largest element in an unsorted array. Note that it was the kth largest element in the sorted order and not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2, return 5.Note:You may assume k are always valid, 1≤k≤array ' s length.This problem let us find the array of the number k, how to ask, of course, the first thought is to sort the array, and then ask to get the number K large. First look at a use of C + + STL in the integration of the sorting method, without our

[Leetcode] [JavaScript] Triangle

[0];7 if(Triangle.length = = 1){8 returnPassed[0];9 }Ten varMin =Infinity; One for(vari = 1; i ){ A varrow =Triangle[i]; - varCurrrow = []; - for(varj = 0; J ){ the varTMP =NULL; - if(j = = 0){ -TMP = row[0] + passed[0]; -}Else if(j = = Row.length-1){ +TMP = Row[j] + passed[j-1]; -}Else{ +TMP = Math.min (Row[j] + passed[j], Row[j] + passed[j-1]); A } at Currrow.push (TMP); - if(i = = Triangle.length

[Leetcode-java] Course Schedule

()) { inttemp = Stack.pop ();//Delete all lines that are connected to the zero-degree point for(inti = 0; i //each deletion of a corresponding in the degree minus one if(Matrix[temp][i] = = 1) {Matrix[temp][i]= 0; Indegree[i]--;//if the minus I corresponds to a degree of 0, it is put into the stack if(Indegree[i] = = 0) Stack.push (i); } } } for(inti = 0; i //determine if there are points that are not zer

Java for Leetcode 131 palindrome Partitioning

Given a string s, partition s such that every substring of the partition are a palindrome.Return all possible palindrome partitioning of S.For example, given s = "AaB",Return[["AA", "B"],["A", "a", "B"]]Problem solving idea One:The S into the left and right two parts, respectively, to find the partition on both sides, and then stick a piece, Java implementation is as follows:static public listResults tleTwo ways to solve problems:Modify the next idea, starting from the left, if the left side is

Java for Leetcode 133 Clone Graph

Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ ' s undirected graph serialization:Nodes is labeled uniquely.We use # as a separator for each node, and, as a separator for node label and each neighbor of the node.As an example, consider the serialized graph {0,1,2#1,2#2,2}.The graph has a total of three nodes, and therefore contains three parts as separated by #.First node is labeled as 0. Connect node 0 to both nodes 1 and 2.Second node is label

Leetcode LRU Cache

; + } - Public voidMovetohead (Node N) { the if(n!=NULL){ * if(Map.containskey (N.key)) { $Node headnext=Head.next;Panax NotoginsengNode npre=N.pre; -Node nnext=N.next; the //Remove n +npre.next=NNext; ANnext.pre=Npre; the } + //put N to head -Node headnext1=Head.next; $n.next=HeadNext1; $Headnext1.pre=N; -head.next=N; -N.pre=head; the}Else return; - }Wuyi Public intRemoveTail () { theNode tailpre=Tail.

[Leetcode] [JavaScript] Contains Duplicate

Contains DuplicateGiven 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 ele ment is distinct.https://leetcode.com/problems/contains-duplicate/ Water a problem to adjust mood.1 /**2 * @param {number[]} nums3 * @return {Boolean}4 */5 varContainsduplicate =function(nums) {6 if(Nums.length = = 0){7 return false;8 }9 varMap = {};Ten fo

Java for Leetcode 102 Binary Tree level Order traversal

Given a binary tree, return the level order traversal of its nodes ' values. (ie, from left-to-right, level by level).For example:Given binary Tree {3,9,20,#,#,15,7} , 3 / 9 / 7Return its level order traversal as:[ 3], [9,20], [15,7]]Problem Solving Ideas:Pre-sequence Traversal (BFS), using a queue to store each layer of elements, the Java implementation is as follows: Public listJava for Leetcode 102 Binary Tree level Order traversa

Java for Leetcode 118 Pascal ' s Triangle II

Given an index K, return the kth row of the Pascal ' s triangle.For example, given k = 3,Return [1,3,3,1] .Problem Solving Ideas:Note that the topic of k equivalent to the k+1, the other copy can be, Java implementation is as follows: Public listJava for Leetcode 118 Pascal ' s Triangle II

Java for Leetcode 077 combinations

Given-integers n and K, return all possible combinations of K numbers out of 1 ... n.For example,If N = 4 and k = 2, a solution is:[ [2,4], [3,4], [ 2,3], [up], [1,3], [1,4],]Problem-solving ideas: Dfs,java realized as follows:public static void Main (String args[]) {listJava for Leetcode 077 combinations

Java for Leetcode 084 largest Rectangle in histogram "hard"

For example,Given height = [2,1,5,6,2,3] ,Return 10 .Problem Solving Ideas:Refer to problem h:largest Rectangle in a histogram fourth idea, or translated version largest Rectangle in [email protected], Java implementation as Under public int Largestrectanglearea (int[] height) { stackJava for Leetcode 084 largest Rectangle in histogram "hard"

[Leetcode]146 LRU Cache

https://oj.leetcode.com/problems/lru-cache/http://blog.csdn.net/linhuanmars/article/details/21310633Publicclasslrucache{publiclrucache (int capacity) {map=newHashMap[Leetcode]146 LRU Cache

Leetcode Problem Summary (algorithm, difficulty, frequency)

Array 120 Triangle 3 1 Array Dp 121 best time to Buy and Sell Stock 2 1 Array Dp 122 best time to Buy and Sell Stock II 3 1 Array Greedy 123 best time to Buy and Sell Stock III 4 1 Array Dp 124 Binary Tree Maximum Path Sum 4 2 Tree Dfs 125 Valid palindrome 2 5

Java [Leetcode 24]swap Nodes in Pairs

Title Description:Given a linked list, swap every, 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. Modify the values in the list, only nodes itself can be changed.Problem Solving Ideas:I just want to say that recursive Dafa is good.The code is as follows:/** * Definition for singly-linked list. * public class ListNode {* int val; * ListNode Next; * listnode (int x) {val = x;}}}

Java for Leetcode 049 anagrams

Given an array of strings, return all groups of strings that is anagrams.Note:all inputs'll is in lower-case.Problem-solving ideas: First of all to understand, what is anagrams,ie. "Tea", "tae", "aet", and then very good to do, new a hashmap, using a sequence of string as key, repeated to add elements to the inside, there is a small episode, is the sort of time do not use Priorityqueue, Because Priorityqueue is sorted by heap, only the top element of the heap is guaranteed to be the highest prio

Total Pages: 15 1 .... 11 12 13 14 15 Go to: Go

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.