- 博客(48)
- 资源 (7)
- 收藏
- 关注
原创 Single Number
题目: Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without usin
2016-08-31 22:44:14 168
转载 Linked List Cycle
题目: Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 分析:此题还是值得考虑的,判断链表有没有环 一开始使用了复杂度O(n^2)的方法,使用两个指针a,b。a从表头开始一步一
2016-08-31 21:17:05 201
原创 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()
2016-08-31 20:17:12 180
原创 Compare Version Numbers
题目: Compare two version numbers version1 and version2. If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0. You may assume that the version strings are non-empty a
2016-08-31 11:03:58 150
原创 Excel Sheet Column Title
题目: Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 分析:移
2016-08-30 21:30:45 178
原创 Majority Element
题目: Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority elem
2016-08-30 20:22:30 193
原创 Rotate Array
题目: Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. Note: Try to come up as many solutions as
2016-08-30 17:18:43 190
原创 Reverse Bits
题目: Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001
2016-08-30 10:22:23 241
原创 Find the Difference
题目: 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 a random position. Find the letter that w
2016-08-29 09:20:53 330
原创 Number of 1 Bits
题目: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). For example, the 32-bit integer ’11' has binary representation 00
2016-08-28 14:56:33 321
转载 求质数
chuanbindeng 的 素数判断算法 关于素数的算法是信息学竞赛和程序设计竞赛中常考的数论知识,在这里我跟大家讲一下寻找一定范围内素数的几个算法。看了以后相信 对大家一定有帮助。 正如大家都知道的那样,一个数 n 如果是合数,那么它的所有的因子不超过sqrt(n)--n的开方,那么我们可以用这个性质用最直观的方法 来求出小于等于n的所有的素数。 num = 0;
2016-08-28 14:56:08 409
原创 House Robber
题目: You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacen
2016-08-28 14:44:23 287
原创 Count Primes
题目: Description: Count the number of prime numbers less than a non-negative number, n. 分析: 计算出一个素数表,然后计算出小于n的素数个数。 代码: class Solution { public: int countPrimes(int n) {
2016-08-28 14:12:11 412
原创 Remove Linked List Elements
题目: Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6 Return: 1 --> 2 --> 3 --> 4 --> 5 分析:考虑多种情况,只有一个节点,前面的节点等
2016-08-28 13:13:10 299
原创 Happy Number
题目: Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squa
2016-08-28 12:51:21 306
原创 Isomorphic Strings
题目: 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 occurrences of a character must be replaced with
2016-08-28 11:54:57 332
原创 Reverse Linked List
题目: Reverse a singly linked list. click to show more hints. 分析:定义三个指针,分别指向当前节点,当前节点的下一个节点,和下一节点的下一节点,然后反转前两个节点,然后当前节点后移。 代码: /** * Definition for singly-linked list. * struct ListNode { *
2016-08-28 11:38:46 297
原创 Pow(x, n)
题目: Implement pow(x, n). Subscribe to see which companies asked this question 分析:n属于INT_MIN时的n=0-n会溢出n的最大值,需特别考虑 代码: class Solution { public: double myPow(double x, int n) {
2016-08-27 21:11:41 330
原创 Contains Duplicate II
题目: Contains Duplicate II Total Accepted: 72866Total Submissions: 237922Difficulty: Easy Given an array of integers and an integer k, find out whether there are two distinct
2016-08-27 19:52:03 302
原创 Lowest Common Ancestor of a Binary Search Tree
题目: Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined
2016-08-27 19:13:35 323
原创 Range Sum Query - Immutable
题目: Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. Example: Given nums = [-2, 0, 3, -5, 2, -1] sumRange(0, 2) -> 1 sumRange(2, 5) -> -1
2016-08-25 16:06:36 140
原创 Implement Stack using Queues
题目: Implement the following operations of a stack using queues. push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Retu
2016-08-25 15:38:09 146
原创 First Bad Version
题目: You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based
2016-08-25 15:14:08 124
原创 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 o
2016-08-25 11:29:11 158
原创 Ugly Number
题目: Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly
2016-08-25 11:22:33 170
原创 Word Pattern
题目: Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.
2016-08-24 22:45:50 204
原创 Bulls and Cows
题目: You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a
2016-08-24 17:19:56 186
转载 灰度共生矩阵
概念 编辑 由于纹理是由灰度分布在空间位置上反复出现而形成的,因而在图像空间中相隔某距离的两象素之间会存在一定的灰度关系,即图像中灰度的空间相关特性。灰度共生矩阵就是一种通过研究灰度的空间相关特性来描述纹理的常用方法。 灰度共生矩阵生成 编辑 灰度直方图是对图像上单个象素具有某个灰度进行统计的结果,而灰度共生矩阵是对图像上保持某距离的两象素分别具有某灰度的状况进行统计得到的。
2016-08-24 15:10:47 945
原创 First Unique Character in a String
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode", return 2. 分析: 使
2016-08-23 09:29:00 243
原创 Power of Three
Given an integer, write a function to determine if it is a power of three. Follow up: Could you do it without using any loop / recursion? 分析:3为质数,3^n最大值对3^n求余为0 代码: class Solution { p
2016-08-22 22:13:14 214
原创 Invert Binary Tree
题目: Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 分析:分析左右子树情况,利用递归 代码: /** * Definition for a binary tree nod
2016-08-22 18:01:28 164
原创 Power of Four
Power of Four Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example: Given num = 16, return true.Given num = 5, return false. Follow up
2016-08-22 16:56:12 183
原创 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]. Note: Each element in the result should appear as many ti
2016-08-22 14:04:28 163
转载 图像处理常用边缘检测算子总结
不同图像灰度不同,边界处一般会有明显的边缘,利用此特征可以分割图像。需要说明的是:边缘和物体间的边界并不等同,边缘指的是图像中像素的值有突变的地方,而物体间的边界指的是现实场景中的存在于物体之间的边界。有可能有边缘的地方并非边界,也有可能边界的地方并无边缘,因为现实世界中的物体是三维的,而图像只具有二维信息,从三维到二维的投影成像不可避免的会丢失一部分信息;另外,成像过程中的光照和噪声也是不可避免
2016-08-21 20:25:12 599
转载 边缘检测之Sobel检测算子
在讨论边缘算子之前,首先给出一些术语的定义: (1)边缘:灰度或结构等信息的突变处,边缘是一个区域的结束,也是另一个区域的开始,利用该特征可以分割图像。 (2)边缘点:图像中具有坐标[x,y],且处在强度显著变化的位置上的点。 (3)边缘段:对应于边缘点坐标[x,y]及其方位 ,边缘的方位可能是梯度角。 二、Sobel算子的基本原理 Sobel算子是一阶导数的边缘检测算子,在算法实现过程
2016-08-21 20:09:12 7302
原创 Intersection of Two Arrays
Intersection of Two Arrays Total Accepted: 39169Total Submissions: 87928Difficulty: Easy Given two arrays, write a function to compute their intersection. Example: Given nu
2016-08-21 16:24:49 235
原创 Binary Tree Paths
Binary Tree Paths Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 / \ 2 3 \ 5 All root-to-leaf paths are: ["1->2->5", "1->3"]
2016-08-21 15:37:40 161
原创 Reverse Integer
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 分析: 求余求商迭代到最后商为0,注意:翻转后的数可能会越界,做好处理 代码: class Solution
2016-08-21 14:29:15 154
原创 Guess Number Higher or Lower
leetcode题目 374. Guess Number Higher or Lower We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you g
2016-08-21 13:50:56 224
原创 直方图均衡化
直方图均衡化 直方图均衡化是图像增强的一种,对灰度较集中的直方图进行拉伸,增加对比度。 图像增强需满足两个条件: 1. 原图像的大小关系不变,即图像增强前后各个像素的大小关系保持不变。 2. 图像所属范围不变,即若8位图像,前后灰度值范围仍为0-255. 直方图均衡化就是把原图像的对应的灰度值通过累积分布函数映射为另一灰度值。 直方图均衡化满足以上两个条件。 直方图均衡化
2016-08-20 19:18:56 580
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人