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
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
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
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
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
()) { 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
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
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
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
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
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
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
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"
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
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;}}}
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
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.