![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode OJ
文章平均质量分 73
思翊
Hello , world.
展开
-
LeetCode OJ 之 Pascal's Triangle II (杨辉三角II )
题目:Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].杨辉sanjNote:Could you optimize your algorithm to use only O(k) extra spa原创 2014-11-08 22:07:10 · 638 阅读 · 0 评论 -
LeetCode OJ 之 Pascal's Triangle(杨辉三角)
题目:Given numRows, generate the first numRows of Pascal's triangle.给定一个数字,求For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]原创 2014-11-08 21:06:49 · 507 阅读 · 0 评论 -
LeetCode OJ 之 Remove Element (删除指定元素)
题目:Given an array and a value, remove all instances of that value in place and return the new length.给定一个数组和一个值,删除The order of elements can be changed. It doesn't matter what you leave b原创 2014-11-09 20:38:43 · 463 阅读 · 0 评论 -
LeetCode OJ 之 Two Sum(两个数的和)
题目:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the ta原创 2014-11-09 21:52:49 · 727 阅读 · 0 评论 -
LeetCode OJ 之 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原创 2014-11-12 23:14:30 · 456 阅读 · 0 评论 -
LeetCode OJ 之 Minimum Depth of Binary Tree(二叉树的最小深度)
题目: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.最小深度是指从根结点到叶结点的最短路径的结点数目。原创 2014-11-12 20:50:06 · 480 阅读 · 0 评论 -
LeetCode OJ 之 Maximum Depth of Binary Tree (二叉树的最大深度)
题目: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.代码:/** * Definition for原创 2014-11-12 21:36:50 · 476 阅读 · 0 评论 -
LeetCode OJ 之 Remove Duplicates from Sorted List(删除有序链表中重复的数)
题目:Given a sorted linked list, delete all duplicates such that each element appear only once.给定一个有序链表,删除所有重复的数字,使得每个元素只For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, ret原创 2014-11-13 12:42:36 · 541 阅读 · 0 评论 -
LeetCode OJ 之 Add Binary (二进制数字相加)
题目:Given two binary strings, return their sum (also a binary string).(给定For example,a = "11"b = "1"Return "100".原创 2014-11-15 11:32:25 · 544 阅读 · 0 评论 -
LeetCode OJ 之 Same Tree (相同树的判断)
题目: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-15 13:52:54 · 638 阅读 · 0 评论 -
LeetCode OJ 之 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 th原创 2014-11-16 09:47:56 · 684 阅读 · 0 评论 -
LeetCode OJ 之 Best Time to Buy and Sell Stock II (买卖股票的最佳时间 2)
题目:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i原创 2014-11-16 11:03:10 · 454 阅读 · 0 评论 -
LeetCode OJ 之 Reorder List (重新排序链表)
题目:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…给定一个链表L:L0→L1→…→Ln-1→Ln排序You must do this in-place without altering the nodes' values.For原创 2014-11-17 11:35:57 · 577 阅读 · 0 评论 -
LeetCode OJ 之 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 ne原创 2014-11-18 22:06:34 · 652 阅读 · 0 评论 -
LeetCode OJ 之 Sort List (排序链表)
题目:Sort a linked list in O(n log n) time using constant space complexity.排序一个链表,要求时间原创 2014-11-21 10:45:59 · 562 阅读 · 0 评论 -
LeetCode OJ 之 Symmetric Tree(对称树)
题目: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 3Bu原创 2014-11-04 21:34:56 · 541 阅读 · 0 评论 -
LeetCode OJ 之 Palindrome Number(回文数字)
题目:Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to str原创 2014-11-04 20:55:33 · 492 阅读 · 0 评论 -
LeetCode OJ 之 Divide Two Integers (两个整数相除)
题目:Divide two integers without using multiplication, division and mod operator.求两个整数相除的结果,不能使用乘除和原创 2014-11-21 21:36:45 · 1079 阅读 · 0 评论 -
LeetCode OJ 之 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 hav原创 2014-11-22 11:46:35 · 547 阅读 · 0 评论 -
LeetCode OJ 之 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 and return it原创 2014-11-22 21:12:27 · 612 阅读 · 0 评论 -
LeetCode OJ 之 Roman to Integer(罗马数字转十进制)
题目:Given a roman numeral, convert it to an integer.(给定一个罗马数字,Input is guaranteed to be within the range from 1 to 3999.原创 2014-11-05 11:40:30 · 1225 阅读 · 0 评论 -
LeetCode OJ 之 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 p原创 2014-11-13 11:50:57 · 647 阅读 · 0 评论 -
LeetCode OJ 之 Insertion Sort List (插入法排序链表)
题目:Sort a linked list using insertion sort.使用插入法排序链表。思路:代码:原创 2014-11-22 23:00:54 · 451 阅读 · 0 评论 -
LeetCode OJ 之 Triangle (三角形)
题目: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-16 11:40:18 · 523 阅读 · 0 评论 -
LeetCode OJ 之 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原创 2014-11-13 22:54:41 · 679 阅读 · 0 评论 -
LeetCode OJ 之 Merge Sorted Array (合并已排好序的数组)
题目:Given two sorted integer arrays A and B, merge B into A as one sorted array.给定两个已经排好序的数组A和B,把Note:You may assume that A has enough space (size that is greater or equal to m + n) to原创 2014-11-06 22:00:00 · 633 阅读 · 0 评论 -
LeetCode OJ 之 Path Sum(求路径和)
题目:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.给一个二叉树和一个For example:Given the belo原创 2014-11-06 20:30:07 · 555 阅读 · 0 评论 -
LeetCode OJ 之 ZigZag Conversion (“Z”转换)
数独原创 2014-11-14 21:13:00 · 461 阅读 · 0 评论 -
LeetCode OJ 之 Binary Tree Level Order Traversal II (二叉树的层次遍历-二)
题目: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,#,原创 2014-11-23 22:59:45 · 463 阅读 · 0 评论 -
LeetCode OJ 之 Valid Sudoku (数独判断)
题目:Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partia原创 2014-11-24 23:04:35 · 618 阅读 · 0 评论 -
LeetCode OJ 之 Compare Version Numbers (比较版本数)
题目:Compare two version numbers version1 and version 2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.比较版本1和版本2,如果版本1 > 版本2,返回1,如果版本1 You may assume原创 2014-12-16 22:22:59 · 943 阅读 · 0 评论 -
LeetCode OJ 之 Remove Duplicates from Sorted Array II (删除有序数组中重复的数-二)
题目:Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?(相同的数最多可以出现两次)For example,Given sorted array A = [1,1,1,2,2,3],Your function should return length =原创 2014-11-26 21:44:35 · 446 阅读 · 0 评论 -
LeetCode OJ 之 Longest Common Prefix (最长公共前缀)
题目:Write a function to find the longest common prefix string amongst an array of strings.写一个函数,找出一个字符串数组内字符串原创 2014-11-12 20:37:10 · 521 阅读 · 0 评论 -
LeetCode OJ 之 N-Queens(N皇后)
题目:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens原创 2015-01-27 13:08:05 · 638 阅读 · 0 评论 -
LeetCode OJ 之 Restore IP Addresses(恢复IP地址)
题目:Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]原创 2015-01-06 10:56:30 · 503 阅读 · 0 评论 -
LeetCode OJ 之 Gray Code(格雷码)
题目: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 seq原创 2015-01-07 09:10:12 · 751 阅读 · 0 评论 -
LeetCode OJ 之 Binary Tree Inorder Traversal (二叉树的中序遍历)
题目:Given a binary tree, return the inorder traversal of its nodes' values.给定一个二叉树,返回中序遍历后结点的值。For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1原创 2014-12-17 09:32:25 · 437 阅读 · 0 评论 -
LeetCode OJ 之 Partition List (划分链表)
题目:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes i原创 2015-01-08 10:15:56 · 465 阅读 · 0 评论 -
LeetCode OJ 之 Search in Rotated Sorted Array (有序数组翻转后的查找)
题目:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the ar原创 2014-12-18 10:37:29 · 1058 阅读 · 0 评论 -
LeetCode OJ 之 Integer to Roman (整数转化为罗马数字)
题目:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.给一个整型数,把他转化成罗马数字。输入范围从1 到 3999。思路:参看罗马数字转化为整数:http://blog.csdn.net/u0122431原创 2015-01-08 08:56:28 · 384 阅读 · 0 评论