随笔分类 - Leetcode
solution to the problems from Leetcode
摘要:Given an unsorted integer array, find the smallest missing positive integer. Example 1: Example 2: Example 3: Note: Your algorithm should run in O(n)
阅读全文
摘要:Basically just clone the graph like clone a list in leetcode 138. there are three ways t solve this (just traverse the graph and put new node into map
阅读全文
摘要:Solution: build tree, how to divide the array for each root and subtree we can use map to get the index of the array for a specific element Solution 2
阅读全文
摘要:1. Solution: add popmax this func, you can pop out max at any time , so max stack to track the max elements does not work as minstack(leetcode 155) di
阅读全文
摘要:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy
阅读全文
摘要:Given a singly linked list, determine if it is a palindrome. Example 1: Example 2: Follow up:Could you do it in O(n) time and O(1) space? Sloving with
阅读全文
摘要:There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every
阅读全文
摘要:Given two strings A and B of lowercase letters, return true if and only if we can swap two letters in A so that the result equals B. Example 1: Input:
阅读全文
摘要:Given a binary tree, return the inorder traversal of its nodes' values. Example: Input: [1,null,2,3] 1 \ 2 / 3 Output: [1,3,2] Follow up: Recursive so
阅读全文
摘要:The ability to debug and overall thinking need to improve Given a string, find the first non-repeating character in it and return it's index. If it do
阅读全文
摘要:Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one more letter at
阅读全文
摘要:Count the number of prime numbers less than a non-negative number, n. Example: Solution2: ssieving: need a helping array with false initialization: fa
阅读全文
摘要:Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrenc
阅读全文
摘要:All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to
阅读全文
摘要:Given a group of two strings, you need to find the longest uncommon subsequence of this group of two strings. The longest uncommon subsequence is defi
阅读全文
摘要:Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the s
阅读全文
摘要:Given an array consists of non-negative integers, your task is to count the number of triplets chosen from the array that can make triangles if we tak
阅读全文
摘要:Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to find the number of connected
阅读全文
摘要:Given an unsorted array of integers, find the length of the longest consecutive elements sequence. Your algorithm should run in O(n) complexity. Examp
阅读全文
摘要:dp or memo recursion 1. dp formulation 2. ispalindrome based on the nature structure 79. Word Search the key point is a||b||c||d; //I guess because of
阅读全文

浙公网安备 33010602011771号