
LeetCode
文章平均质量分 94
曲小鑫
我的学习笔记
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
leetcode | Maximum Gap
Maximum Gap: https://leetcode.com/problems/maximum-gap/ Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Ret原创 2015-07-20 15:05:36 · 635 阅读 · 0 评论 -
leetcode | Merge Intervals
Merge Intervals : https://leetcode.com/problems/merge-intervals/Given a collection of intervals, merge all overlapping intervals.For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15原创 2015-07-25 17:28:03 · 554 阅读 · 0 评论 -
leetcode | Balanced Binary Tree
Balanced Binary Tree : https://leetcode.com/problems/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原创 2015-07-03 14:37:03 · 718 阅读 · 0 评论 -
leetcode | Path Sum II
Path Sum II : https://leetcode.com/problems/path-sum-ii/ 解析: 和上一题的区别就是,要记录所有能满足条件的路径。 要保存当前的结果,并且每次递归后都要恢复递归前的结果;每当递归到叶子节点时,判断是否需要当前结果(path)保存下来。 叶节点时 sum == 0, 保存当前结果,然后逐步恢复递归前结果 叶节点时 sum != 0,不保原创 2015-07-03 16:44:04 · 915 阅读 · 0 评论 -
leetcode | Implement strStr() | 实现字符串查找函数
Implement strStr() : https://leetcode.com/problems/implement-strstr/Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 如:haystack = “bcbcda”; nee原创 2015-07-05 15:29:44 · 2699 阅读 · 0 评论 -
leetcode | Minimum Depth of Binary Tree
Minimum Depth of Binary Tree : https://leetcode.com/problems/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 fr原创 2015-07-03 15:12:54 · 580 阅读 · 0 评论 -
leetcode | Path Sum
Path Sum :https://leetcode.com/problems/path-sum/ 解析:求根到叶节点路径上所有节点的和等于target的值 即判断是否存在 一个叶节点的值等于target;如何判断一个节点是叶节点:该节点本身非空,左右节点为空。/** * Definition for a binary tree node. * struct TreeNode { *原创 2015-07-03 15:47:35 · 633 阅读 · 0 评论 -
二叉树遍历的非递归实现
本文和该篇文章 leetcode | 二叉树的前序遍历、中序遍历、后续遍历的非递归实现有不同的实现方式,此文章的非递归遍历实现算法,易于理解和实现。包含插入、遍历、统计树中节点的个数、统计树的深度等操作。 遍历操作包含: - 迭代(非递归)实现的前序、中序、后序、层序遍历。其中前序和中序,一个是先访问在入栈、一个是先入栈后访问有极大的相似性; 其中后序遍历使用了双栈操作,使思想简化易于实现原创 2015-06-24 19:09:19 · 799 阅读 · 0 评论 -
leetcode | 二叉树的前序遍历、中序遍历、后续遍历的非递归实现
Binary Tree Preorder Traversal:https://leetcode.com/problems/binary-tree-preorder-traversal/ Binary Tree Inorder Traversal :https://leetcode.com/problems/binary-tree-inorder-traversal/ Binary Tree Po原创 2015-06-01 19:20:05 · 3309 阅读 · 0 评论 -
leetcode | Climbing Stairs
Climbing Stairs : https://leetcode.com/problems/climbing-stairs/You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct way原创 2015-06-23 08:29:36 · 661 阅读 · 0 评论 -
leetcode | Maximum Subarray 最大连续子序列的和
Maximum Subarray: https://leetcode.com/problems/maximum-subarray/ Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [原创 2015-06-23 11:27:52 · 3059 阅读 · 0 评论 -
leetcode | Min Stack
Min Stack: https://leetcode.com/problems/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() – Remov原创 2015-06-22 15:03:29 · 965 阅读 · 0 评论 -
leetcode | Minimum Path Sum
Minimum Path Sum : https://leetcode.com/problems/minimum-path-sum/Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers a原创 2015-07-25 21:18:10 · 592 阅读 · 0 评论 -
2014 年华为校园招聘机试题
试题一、字符串过滤(60分):通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串过滤程序,若字符串中出现多个相同的字符,将非首次出现的字符过滤掉。 比如字符串“abacacde”过滤结果为“abcde”。 要求实现函数: void stringFilter(const char *pInputStr, long lInputLen, char *pOutputStr); 【输入原创 2015-06-15 11:34:34 · 577 阅读 · 0 评论 -
leetcode | ZigZag Conversion
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原创 2015-07-20 16:40:27 · 645 阅读 · 0 评论 -
leetcode | Swap Nodes in Pairs in a linklist
Swap Nodes in Pairs : https://leetcode.com/problems/swap-nodes-in-pairs/Given a linked list, swap every two adjacent nodes and return its head.For example, Given 1->2->3->4, you should return the list原创 2015-07-18 09:55:59 · 597 阅读 · 0 评论 -
leetcode | Intersection of Two Linked Lists
Intersection of Two Linked Lists : https://leetcode.com/problems/intersection-of-two-linked-lists/Write a program to find the node at which the intersection of two singly linked lists begins.For exampl原创 2015-07-18 19:54:43 · 537 阅读 · 0 评论 -
leetcode | Power of Two
Power of Two : https://leetcode.com/problems/power-of-two/ Given an integer, write a function to determine if it is a power of two.判断一个数是否是2的幂? 当无从下手时,可以根据例子找出规律。对于1,2,4,8,16它们的二进制表示分别是: 1: (1) 2:原创 2015-07-18 19:21:50 · 555 阅读 · 0 评论 -
leetcode | sqrt(x)
sqrt(x) : https://leetcode.com/problems/sqrtx/Implement int sqrt(int x). Compute and return the square root of x.解析: 容易想到的是用二分法去试,但收敛速度太慢,不能满足时间要求。 我们知道求根公式,牛顿迭代法 点击查看维基百科 首先,选择一个接近函数f(x)零点的x_0,计原创 2015-07-18 18:47:38 · 665 阅读 · 0 评论 -
leetcode | Reverse Nodes in k-Group
Reverse Nodes in k-Group : https://leetcode.com/problems/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原创 2015-07-18 16:12:19 · 593 阅读 · 0 评论 -
leetcode | Pow(x, n)
Pow(x, n) : https://leetcode.com/problems/powx-n/Implement pow(x, n).解析: 同剑指offer: 数值的整数次方 | Power本题考查的关键点有:double 不能使用“==” 0 不能取负数次幂任何数的 0 次幂为 11的任何次幂为1-1的偶数次幂为1,奇数次幂为-1如何快速的计算一个数的整数次幂注意: 关于基数原创 2015-07-18 16:49:14 · 609 阅读 · 0 评论 -
leetcode | String to Integer (atoi)
String to Integer (atoi) : https://leetcode.com/problems/string-to-integer-atoi/问题描述Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a cha原创 2015-06-14 20:50:30 · 510 阅读 · 0 评论 -
leetcode | Add Binary
Add Binary: https://leetcode.com/problems/add-binary/Given two binary strings, return their sum (also a binary string).For example, a = “11” b = “1” Return “100”.本题关键点在于: 1. 从后往前计算,但是结果字符串应该是从最前插入每原创 2015-06-15 15:38:28 · 692 阅读 · 0 评论 -
leetcode | LRU Cache
LRU Cache : https://leetcode.com/problems/lru-cache/ Degree: hardDesign and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get原创 2015-06-13 17:53:44 · 714 阅读 · 0 评论 -
leetcode | Insert Interval
Insert Interval : https://leetcode.com/problems/insert-interval/Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals原创 2015-07-25 20:33:17 · 684 阅读 · 0 评论 -
leetcode | Rotate List
Rotate List :https://leetcode.com/problems/rotate-list/问题描述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->原创 2015-06-01 10:55:15 · 704 阅读 · 0 评论 -
leetcode | Valid Palindrome
Valid Palindrome : https://leetcode.com/problems/valid-palindrome/Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example, “A man, a pl原创 2015-06-21 16:44:19 · 749 阅读 · 0 评论 -
leetcode | Merge Sorted Array
Merge Sorted Array Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n)原创 2015-05-13 10:30:45 · 568 阅读 · 0 评论 -
leetcode | Reverse Words in a String
问题Reverse Words in a String Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the". Update (2015-02-12): For C programmers: Tr原创 2015-05-05 10:54:27 · 602 阅读 · 0 评论 -
leetcode 8. 将整数的位数反序 Reverse Integer
Reverse IntegerReverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321解答容易想到本题用整数取余运算和整除运算结合;需要注意的是溢出的问题: 从题目来看,输入时在int之内的数,即不会溢出,但是去反序后的数则可能超出int的范围。数据类型的边界值问题,详见原创 2015-05-03 10:47:27 · 825 阅读 · 0 评论 -
leetcode 9. 判断整数是否是回数 Palindrome Number
Palindrome NumberDetermine whether an integer is a palindrome. Do this without extra space.注:回数是指正读和倒读都一样的数:需要注意点 (1)负数不是回数 (2)个位数都是回数 思路: (1)使用前一题的整数的倒序,将一个数倒序,然后和原值比较:存在的问题是可能有溢出原创 2015-05-03 16:02:27 · 936 阅读 · 1 评论 -
leetcode 6. 在有序数组旋转后搜索 Search in Rotated Sorted Array
Search in Rotated Sorted Array 难度:HardSuppose 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原创 2015-04-27 15:36:11 · 1065 阅读 · 0 评论 -
leetcode | Median of Two Sorted Arrays 寻找2个有序数组中第k大的值
问题 Median of Two Sorted ArraysThere are two sorted arrays A and B 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)).分析本题更经原创 2015-05-10 17:12:12 · 2451 阅读 · 0 评论 -
leetcode 7. 在有序可重复数组旋转后搜索 Search in Rotated Sorted Array II
Search in Rotated Sorted Array IIFollow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a原创 2015-04-27 16:27:43 · 914 阅读 · 0 评论 -
leetcode 4. 移除有序数组中的重复元素 Remove Duplicates from Sorted Array
问题:Remove Duplicates from Sorted Array II 难度:mediumFollow 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 s原创 2015-04-25 10:53:48 · 752 阅读 · 0 评论 -
leetcode 3. 移除链表的倒数第n个节点 Remove Nth Node From End of List
问题:Remove Nth Node From End of List 难度:mediumGiven 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 t原创 2015-04-25 09:40:07 · 646 阅读 · 0 评论 -
leetcode 5. 两个链表逐个元素相加 Add Two Numbers
问题:Add Two Numbers 难度-MediumYou 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 nu原创 2015-04-25 16:23:07 · 1603 阅读 · 0 评论 -
leetcode 2. 从有序链表和数组中移出重复元素 Remove Duplicates
1. 链表 Remove Duplicates from Sorted ListGiven 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, return原创 2015-04-24 16:11:41 · 1238 阅读 · 0 评论 -
leetcode | Merge Two Sorted Lists
Merge Two Sorted ListsMerge 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.C实现/** * Definition for singly-linke原创 2015-05-13 10:55:23 · 659 阅读 · 0 评论 -
leetcode | Text Justification
问题Text Justification 解析根据问题描述,需要注意的点有: - 1. 如何获得具有最多word的一行: 有效字符串的长度+间隔的个数 <= maxWidth - 2. 计算单词之间的空格数:每行单词之间的空格数不等时,如何处理? - 将平分后剩余的空格,从前往后,每个间隔补上一个空格 - 3. 只有一个单词 - 4. 最后一行要原创 2015-05-05 17:27:27 · 729 阅读 · 0 评论