
leetcode
noc_lemontree
踏实走。
展开
-
[leetcode单元总结]hash table部分easy篇小总结
在difficulty为easy的hash table部分,没有用到常见的哈希算法,更多的是借用数组的下标来实现。对于下标的操作看起来很简单,其实需要细致和耐心,可能一个小错误,比如下标字母弄错用成了上个循环使用的下标(t.t’),结束条件没写对等等就会导致错误。 A.在Valid Sudoku 中,判断中拓宽了思维,1。多动脑子,小九宫格中,将每个小个子的下标与第几个联系起来。2。对于一般的含有原创 2015-08-30 15:17:27 · 1047 阅读 · 0 评论 -
[leetcode]Isomorphic Strings C语言
【题目】 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 ano原创 2015-08-29 16:19:46 · 1115 阅读 · 0 评论 -
[leetcode]Rotate Array C语言
【题目】 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 you原创 2015-08-22 16:58:10 · 455 阅读 · 0 评论 -
[leetcode]Remove Duplicates from Sorted Array C语言
【题目】 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 w原创 2015-08-22 17:51:38 · 1528 阅读 · 0 评论 -
[leetcode]Count Primes C语言
【题目】 Count the number of prime numbers less than a non-negative number, n. Credits: Special thanks to @mithmatt for adding this problem and creating all test cases. 【题目分析】 这道题常用的判断一个数是否为质数是行不通的,根据原创 2015-08-30 14:44:11 · 1473 阅读 · 0 评论 -
[leetcode]Power of Two C语言
【题】 Given an integer, write a function to determine if it is a power of two. 【具体代码如下】 bool isPowerOfTwo(int n) { int i; if(n<1)return false; while(n!=1) { i=n%2; if(i=原创 2015-09-08 14:57:23 · 897 阅读 · 0 评论 -
[leetcode] Length of Last Word C语言
【题目】Length of Last World Given a string s consists of upper/lower-case alphabets and empty space characters ’ ‘, return the length of last word in the string.If the last word does not exist, return 0.原创 2015-08-20 10:02:19 · 671 阅读 · 0 评论 -
[leetcode]Valid Anagram C语言
【题目】 Given two strings s and t, write a function to determine if t is an anagram of s.For example, s = “anagram”, t = “nagaram”, return true. s = “rat”, t = “car”, return false.Note: You may assume原创 2015-08-29 15:23:09 · 1839 阅读 · 1 评论 -
[leetcode]Palindrome Number C 语言
【题】 Determine whether an integer is a palindrome. Do this without extra space.【具体代码如下】bool isPalindrome(int x) { int stack[10]={-1}; if(x<0) return false; if(x==0)return true; int tmp;原创 2015-09-08 15:49:14 · 705 阅读 · 0 评论 -
[leetcode]unique-paths 动态规划 C++
题目:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to r原创 2016-07-13 15:21:56 · 693 阅读 · 2 评论 -
[leetcode]climbing-stairs 动态规划 C++
题目: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 ways can you climb to the top?题目分析:这也是一道简单而典型原创 2016-07-13 16:28:51 · 918 阅读 · 0 评论 -
[leetcode]Merge Sorted Array C语言
【题目】 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) to hold ad原创 2015-08-27 16:14:02 · 965 阅读 · 0 评论 -
[leetcode]Contains Duplicate II C语言
【题目】 Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k. 【题目原创 2015-08-28 15:58:03 · 970 阅读 · 0 评论 -
[leetcode]Majority Element C语言
【题目】 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 element原创 2015-08-27 18:06:24 · 1601 阅读 · 0 评论 -
[leetcode]Plus One C语言
【题目】 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.【题目分析】 这道题的关键在于最高位有没原创 2015-08-27 15:23:14 · 2205 阅读 · 0 评论 -
[leetcode]Valid Sudoku C 语言
【题目】 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 ‘.’.Note: A valid Sudoku boar原创 2015-08-29 14:43:21 · 1113 阅读 · 0 评论 -
[leetcode]Remove Element C语言
【题目】 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 beyond the new length.【题原创 2015-08-22 17:24:29 · 1490 阅读 · 0 评论 -
[leetcode]Ugly Number C语言
【题目】 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 sin原创 2015-08-30 16:04:13 · 970 阅读 · 0 评论 -
[leetcode]Happy Number C语言
【题目】 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原创 2015-08-29 21:00:48 · 2462 阅读 · 0 评论 -
[leetcode]Roman to Integer C语言
【题目】 Roman to Integer Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.【题目分析】首先,罗马数字的表示必须要清楚,这一点上网查。【具体代码如下】int toNumber(char ch) {原创 2015-08-20 09:49:08 · 2177 阅读 · 0 评论 -
[leetcode]Contains Duplicate C语言
【题目】 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 eleme原创 2015-08-27 20:58:45 · 1124 阅读 · 0 评论 -
[leetcode]Valid Palindrome C语言
[leetcode]Valid Palindrome解题报告 C语言Valid Palindrome Given a string,determine if it is a palindrome, considering only alphanumeric characters andignoring cases. For example, “A man, a plan,a canal: Pa原创 2015-08-20 09:33:19 · 638 阅读 · 0 评论 -
[leetcode]Reverse Integer C语言
【题】 Reverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321click to show spoilers. Have you thought about this? Here are some good questions to ask before coding.原创 2015-09-01 10:53:01 · 799 阅读 · 0 评论 -
[leetcode]maximum-depth-of-binary-tree C++
题目: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.分析:此题用递归的方式做非常简单,虽然一次性就通过原创 2016-07-13 21:41:00 · 397 阅读 · 0 评论