![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
artemisrj
这个作者很懒,什么都没留下…
展开
-
【leetcode】104. Maximum Depth of Binary Tree 92.83%
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.Subscribe to see which companies asked this原创 2016-05-17 15:16:34 · 236 阅读 · 0 评论 -
【leetcode】20. Valid Parentheses
Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the correct order, “()” and “()[]{}” are all valid but “原创 2016-07-05 10:34:29 · 309 阅读 · 0 评论 -
【leetcode】350. Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection.Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].Your runtime beats 38.36% of javascriptsubmissions/** * @param {n原创 2016-06-19 08:36:44 · 317 阅读 · 0 评论 -
【leetcode】19. Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linke原创 2016-07-04 20:07:26 · 241 阅读 · 0 评论 -
【leetcode】46. Permutations
Given a collection of distinct numbers, return all possible permutations.For example, [1,2,3] have the following permutations: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2原创 2016-07-15 11:33:48 · 281 阅读 · 0 评论 -
【leetcode】62. Unique Paths
class Solution {private: int backtrack(int r,int c,int m,int n){ if(r==m-1&&c==n-1){ return 1; } if(r>=m||c>=n){ return 0; } return b原创 2016-07-15 10:45:46 · 273 阅读 · 0 评论 -
【leetcode】28. Implement strStr()
第一种,javascript原生态函数,108ms/** * @param {string} haystack * @param {string} needle * @return {number} */var strStr = function(haystack, needle) { return haystack.indexOf(needle);};第二种,朴素字符串匹配原创 2016-07-15 10:39:57 · 395 阅读 · 0 评论 -
【leetcode】17. Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below. Input:Digit string “23原创 2016-07-04 12:33:52 · 259 阅读 · 0 评论 -
【leetcode】16. 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly原创 2016-07-04 11:57:06 · 227 阅读 · 0 评论 -
【leetcode】15. 3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain duplic原创 2016-07-03 20:31:02 · 365 阅读 · 0 评论 -
【leetcode】1. 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, 11原创 2016-06-17 11:03:46 · 252 阅读 · 0 评论 -
【leetcode】21. Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Definition for singly-linked list. * function ListNo原创 2016-07-05 10:36:31 · 264 阅读 · 0 评论 -
【leetcode】24. Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example, Given1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You may not原创 2016-07-05 19:40:28 · 297 阅读 · 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.The order原创 2016-07-08 09:53:01 · 350 阅读 · 0 评论 -
【leetcode】26. Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with cons原创 2016-07-07 11:53:29 · 296 阅读 · 0 评论 -
【leetcode】2. 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 a原创 2016-06-20 19:21:13 · 248 阅读 · 0 评论 -
【leetcode】sql练习
以前数据库没有好好上,补一下这方面的基础知识。175. Combine Two TablesTable: Person +————-+———+ | Column Name | Type | +————-+———+ | PersonId | int | | FirstName | varchar | | LastName | varcha原创 2016-06-20 19:14:00 · 1383 阅读 · 0 评论 -
【leetcode】53. Maximum Subarray
53. 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 subar原创 2016-07-17 16:45:53 · 538 阅读 · 0 评论 -
【leetcode】63. Unique Paths II
Follow up for “Unique Paths”:Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the grid.For ex原创 2016-07-17 13:47:40 · 409 阅读 · 0 评论 -
【leetcode】25. 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-07-06 15:29:15 · 268 阅读 · 0 评论 -
【leetcode】23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity./** * Definition for singly-linked list. * function ListNode(val) { * this.val = val; * thi原创 2016-07-06 13:50:43 · 236 阅读 · 0 评论 -
【leetcode】110. Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by原创 2016-07-16 13:46:43 · 339 阅读 · 0 评论 -
【leetcode】66. Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.class Solution {public:原创 2016-07-16 12:12:15 · 379 阅读 · 0 评论 -
【leetcode】14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings./** * @param {string[]} strs * @return {string} */var longestCommonPrefix = function(strs) { var ll = strs.原创 2016-07-03 10:51:44 · 260 阅读 · 0 评论 -
【leetcode】11. Container With Most Water
Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lin原创 2016-07-03 10:15:42 · 232 阅读 · 0 评论 -
【leetcode】6. ZigZag Conversion
The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I原创 2016-06-22 12:57:44 · 556 阅读 · 0 评论 -
【leetcode】238. Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O(n).For e原创 2016-05-19 17:01:46 · 270 阅读 · 0 评论 -
【leetcode】237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, t原创 2016-05-18 16:58:59 · 267 阅读 · 0 评论 -
【leetcode】 260. Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given nums = [1,原创 2016-05-17 18:45:04 · 325 阅读 · 0 评论 -
【leetcode】283. Move Zeroes
Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling your funct原创 2016-05-17 18:31:15 · 350 阅读 · 0 评论 -
【leetcode】226. Invert Binary Tree
照例要考虑树为空的情况。/** * Definition for a binary tree node. * function TreeNode(val) { * this.val = val; * this.left = this.right = null; * } *//** * @param {TreeNode} root * @return {TreeNod原创 2016-05-17 15:25:29 · 205 阅读 · 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原创 2016-05-17 15:13:52 · 223 阅读 · 0 评论 -
【leetcode】343. Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, return 1原创 2016-05-25 18:55:03 · 238 阅读 · 0 评论 -
【leetcode】319. Bulb Switcher
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 third bulb (turning on if it’s off or turning off i原创 2016-05-25 18:53:41 · 290 阅读 · 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 is原创 2016-05-25 18:47:34 · 236 阅读 · 0 评论 -
【leetcode】4. Median of Two Sorted Arrays
leetcod There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1: nums1 = [原创 2016-06-24 10:43:40 · 375 阅读 · 0 评论 -
【leetcode】347. Top K Frequent Elements
Top K Frequent ElementsGiven a non-empty array of integers, return the k most frequent elements.For example, Given [1,1,1,2,2,3] and k = 2, return [1,2].这个办法是先哈希,再排序,等过段时间实现小根堆的算法。/** * @param {numb原创 2016-05-22 20:15:25 · 324 阅读 · 0 评论 -
【leetcode】10. Regular Expression Matching
Implement regular expression matching with support for ‘.’ and ‘*’. ‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element. The matching should cover the entire i原创 2016-07-02 20:03:31 · 359 阅读 · 0 评论 -
[leetcode]344. Reverse String
Write a function that takes a string as input and returns the string reversed.Example: Given s = “hello”, return “olleh”.Subscribe to see which companies asked this question不知道自己会不会精分 javascript版本/**原创 2016-05-14 21:18:44 · 487 阅读 · 0 评论 -
【leetcode】121. Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), desi原创 2016-06-15 19:39:17 · 305 阅读 · 0 评论