![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 53
Shawn_Redemption
这个作者很懒,什么都没留下…
展开
-
【Leetcode】3Sum (Sum)
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:Elements in a triplet (a,b,c原创 2014-11-07 10:45:02 · 311 阅读 · 0 评论 -
【Leetcode】3Sum Closest (Sum)
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 exact原创 2014-11-07 12:19:49 · 270 阅读 · 0 评论 -
【Leetcode】4Sum (Sum)
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Element原创 2014-11-07 13:15:10 · 305 阅读 · 0 评论 -
【Leetcode】Binary Tree Level Order Traversal (Tree 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 20原创 2014-11-08 03:07:52 · 284 阅读 · 0 评论 -
【Leetcode】Binary Tree Level Order Traversal II (Tree Traversal)
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7},原创 2014-11-08 03:32:46 · 336 阅读 · 0 评论 -
【Leetcode】Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.这道题和原创 2014-11-08 09:33:03 · 282 阅读 · 0 评论 -
【Leetcode】Convert Sorted Array to Binary Search Tree (BST)
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.基本方法就是divide and conquerba原创 2014-11-07 23:13:01 · 274 阅读 · 0 评论 -
【Leetcode】Balanced Binary Tree (Tree Judge)
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 diffe原创 2014-11-09 11:54:33 · 347 阅读 · 0 评论 -
【Leetcode】Convert Sorted List to Binary Search Tree (BST)
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.原创 2014-11-08 00:04:42 · 452 阅读 · 0 评论 -
【Leetcode】Binary Tree Zigzag Level Order Traversal (Tree Traversal)
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary原创 2014-11-08 04:23:36 · 243 阅读 · 0 评论 -
【Leetcode】Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.其实这道题弄清楚分段,思想还是挺简单的preorder的分段:原创 2014-11-08 05:22:01 · 356 阅读 · 0 评论 -
【Leetcode】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.这道题huang'yan原创 2014-11-08 23:06:25 · 231 阅读 · 0 评论 -
【Leetcode】Populating Next Right Point in Each Node (TL)
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node.原创 2014-11-09 02:49:27 · 430 阅读 · 0 评论 -
【Leetcode】Same Tree (Tree Judge)
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.原创 2014-11-09 11:51:26 · 340 阅读 · 0 评论 -
【Leetcode】Flatten Binary Tree to Linked List (other)
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1原创 2014-11-09 00:17:36 · 453 阅读 · 0 评论 -
【Leetcode】Symmetric Tree (Tree Judge)
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the f原创 2014-11-09 11:53:35 · 311 阅读 · 0 评论 -
【Leetcode】Validate Bunary Search Tree (Tree Judge)
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.Th原创 2014-11-09 11:57:43 · 371 阅读 · 0 评论 -
【Leetcode】Maximum Depth of Binary Tree (Tree Judge)
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.原创 2014-11-09 12:01:46 · 306 阅读 · 0 评论 -
【Leetcode】Populating Next Right Point in Each Node II (TL)
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node.原创 2014-11-09 02:55:28 · 351 阅读 · 0 评论 -
【Leetcode】Subsets (Backtracking)
Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For exa原创 2014-11-10 00:46:57 · 405 阅读 · 0 评论 -
【Leetcode】Valid Sudoku
public boolean isValidSudoku(char[][] board) { if (board == null || board.length != 9 || board[0].length != 9) return false; for (int i = 0; i < 9; i++) { boolean[] table = new boolean[9];原创 2014-11-10 03:39:39 · 269 阅读 · 0 评论 -
【Leetcode】Jump Game (DP)
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine i原创 2014-11-10 05:27:31 · 363 阅读 · 0 评论 -
【Leetcode】Jump Game II (DP)
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal i原创 2014-11-10 09:26:48 · 317 阅读 · 0 评论 -
【Leetcode】Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as原创 2014-11-10 10:06:50 · 1025 阅读 · 0 评论 -
【Leetcode】Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".这是一道二进制加法题,注意进位和原创 2014-11-10 10:36:27 · 296 阅读 · 0 评论 -
【Leetcode】Minimum Depth of Binary Tree (Tree Judge)
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.递归思路,左右叶子记录各自的深度,返回左右叶子的最小深度+1 即原创 2014-11-09 12:02:31 · 345 阅读 · 0 评论 -
【Leetcode】Gray Code (Pascal)
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of原创 2014-11-10 00:03:37 · 380 阅读 · 0 评论 -
【Leetcode】Next Permutation
public void nextPermutation(int[] num) { if(num==null||num.length==0) return; int i=num.length-2; while(i>=0&&num[i]>=num[i+1]) i--; if(i>=0) {原创 2014-11-10 04:29:46 · 280 阅读 · 0 评论 -
【Leetcode】Subsets II (Backtracking)
public ArrayList> subsetsWithDup(int[] num) { ArrayList> result = new ArrayList>(); result.add(new ArrayList()); if (num == null || num.length == 0) return result; Arrays.sort(num); int s原创 2014-11-10 02:52:41 · 357 阅读 · 0 评论 -
【Leetcode】Triangle (DP)
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], [原创 2014-11-11 07:19:51 · 374 阅读 · 0 评论 -
【Leetcode】ZigZag Conversion
public String convert(String s, int nRows) { if (s == null || s.length() == 0 || nRows <= 0) return ""; if (nRows == 1) return s; StringBuilder res = new StringBuilder(); int size = 2 *原创 2014-11-11 08:44:26 · 345 阅读 · 0 评论 -
【Leetcode】Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a原创 2014-11-11 00:24:59 · 320 阅读 · 0 评论 -
【Leetcode】Remove Element (Removing)
Given an array and a value, remove all instances of that value in place and return the new length.这道题是让删除特定的元素,所以我们用count来记录特定元素记录的ci'shi原创 2014-10-26 04:20:02 · 286 阅读 · 0 评论 -
【Leetcode】Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.这道题最糟糕的su原创 2014-10-26 04:55:46 · 289 阅读 · 0 评论 -
【Leetcode】Rotate Image (Rotated)
此题让把一个二维数组顺时针旋转原创 2014-10-26 08:22:44 · 327 阅读 · 0 评论 -
【Leetcode】Remove Nth Node From End of the List (lastN)
此题让删除链表中的倒数第K个元素,思路如下原创 2014-10-25 08:37:33 · 332 阅读 · 0 评论 -
【Leetcode】Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get原创 2014-11-10 23:10:45 · 350 阅读 · 0 评论 -
【Leetcode】Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.这道题典型cai'yon原创 2014-11-10 23:51:35 · 376 阅读 · 0 评论 -
【Leetcode】Rotate List (lastN)
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.这道题rang原创 2014-10-25 23:02:45 · 358 阅读 · 0 评论 -
【Leetcode】Find Minimum in Rotated Sorted Array
这道题的思路是直接找旋转数组中的最小值原创 2014-10-22 09:19:10 · 374 阅读 · 0 评论