leetcode题解
文章平均质量分 55
u010013453
这个作者很懒,什么都没留下…
展开
-
Leetcode题解 - 461. Hamming Distance
描述见链接其实本质上很简单就是一个位运算的题目,将两个数按位异或之后统计二进制结果中的数字1的个数就行,代码如下:class Solution {public: int hammingDistance(int x, int y) { int z=x^y; int count=0; while((z!=0)){ if(z%2==1)原创 2017-02-25 17:55:42 · 197 阅读 · 0 评论 -
Leetcode题解 - 554. Brick Wall
here is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. You want to draw a vertical line from the top to the b原创 2017-05-15 11:27:28 · 415 阅读 · 0 评论 -
Leetcode题解 - 14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. 链接给定的字符串存在一个数组中,将第一个字符串作为参考,把后续的字符串依次与strs[0]进行比较即可,双重循环即可完成。class Solution {public:string longestCommonPrefix(原创 2017-05-08 10:20:02 · 206 阅读 · 0 评论 -
Leetcode题解 - 20. 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 all valid原创 2017-06-04 21:39:13 · 208 阅读 · 0 评论 -
Leetcode题解 - 61. 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->5->1->2->3->NULL. 链接先遍历一次链表找到链表长度,根据要原创 2017-06-04 21:43:53 · 184 阅读 · 0 评论 -
Leetcode题解 - 200. Number of Islands
Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume原创 2017-06-16 14:38:21 · 310 阅读 · 0 评论 -
Leetcode题解 - 150. Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples: [“2”,原创 2017-05-22 11:13:45 · 296 阅读 · 0 评论 -
Leetcode题解 - 322. Coin Change
You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money c原创 2017-07-04 20:09:07 · 236 阅读 · 0 评论 -
Leetcode题解 - 3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given “abcabcbb”, the answer is “abc”, which the length is 3.Given “bbbbb”, the answer is “b”, with the le原创 2017-07-04 22:00:55 · 218 阅读 · 0 评论 -
Leetcode题解 - 565. Array Nesting
A zero-indexed array A consisting of N different integers is given. The array contains all integers in the range [0, N - 1]. Sets S[K] for 0 <= K < N are defined as follows: S[K] = { A[K], A[原创 2017-07-04 22:12:17 · 266 阅读 · 0 评论 -
Leetcode题解 - 22. Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ “((()))”, “(()())”,原创 2017-04-21 14:09:53 · 278 阅读 · 0 评论 -
Leetcode题解 - 89. 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 sequence of g原创 2017-04-14 15:32:21 · 322 阅读 · 0 评论 -
Leetcode题解 - 387. 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.原创 2017-03-24 14:02:56 · 214 阅读 · 0 评论 -
Leetcode题解 - 53. Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray [4,-1,2,1]原创 2017-03-07 12:50:01 · 284 阅读 · 0 评论 -
Leetcode题解 - 215. Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example, Given [3,2,1,5,6,4] and k = 2, return 5原创 2017-03-11 20:31:56 · 268 阅读 · 0 评论 -
Leetcode题解 - 139. Word Break
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words. You may assum原创 2017-03-21 17:44:22 · 302 阅读 · 0 评论 -
Leetcode题解 - 208. Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods. Note: You may assume that all inputs are consist of lowercase letters a-z. 戳我Trie即字典树或者前缀树,如给出字符串”abc”,”ab”,”bd”,”dda”,根据该字符串序列构建一棵原创 2017-03-31 14:32:41 · 298 阅读 · 0 评论 -
Leetcode题解 - 4. Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 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)). Example 1: nu转载 2017-04-10 11:33:29 · 305 阅读 · 0 评论 -
Leetcode题解 - 495. Teemo Attacking
In LLP world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo’s attacking ascending time series towards Ashe and the poisoning time原创 2017-03-24 13:42:23 · 495 阅读 · 0 评论 -
Leetcode题解 - 56. 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,18]. 链接把交叉的区间进行合并,比较简单的方法就是先把给定的区间按照左边元素的大小进行排序,然后两两相邻原创 2017-03-24 13:48:00 · 444 阅读 · 0 评论 -
Leetcode题解 - 445. Add Two Numbers II
You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return it原创 2017-03-31 15:02:47 · 282 阅读 · 0 评论 -
Leetcode题解 - 55. Jump Game
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原创 2017-03-31 15:11:53 · 261 阅读 · 0 评论 -
Leetcode题解 - 337. House Robber III
The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the “root.” Besides the root, each house has one and only one parent house. After a tour,原创 2017-07-04 22:40:58 · 225 阅读 · 0 评论