
【LeetCode】
「已注销」
随缘。。。随缘。。。。。
展开
-
Leetcode#412. Fizz Buzz
Write a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. Fo原创 2017-07-10 17:15:13 · 320 阅读 · 0 评论 -
Leetcode#:557. Reverse Words in a String III
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Input: "Let's take LeetCode contes原创 2017-07-10 20:07:45 · 258 阅读 · 0 评论 -
Leetcode#389. Find the Difference(位运算=异或)
389. Find the DifferenceGiven 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 positi原创 2017-07-12 11:39:51 · 316 阅读 · 0 评论 -
Leetcode#371. Sum of Two Integers (位运算实现加法)
371. Sum of Two Integers Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.Credits:Special thanks t原创 2017-07-12 13:26:36 · 347 阅读 · 0 评论 -
Leetcode#169. 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 element原创 2017-07-16 12:08:42 · 573 阅读 · 0 评论 -
Leetcode# 268. Missing Number(异或)
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm sho原创 2017-07-16 19:28:17 · 476 阅读 · 0 评论 -
20个位运算技巧
一提起位运算,人们往往想到它的高效性,无论是嵌入式编程还是优化系统的核心代码,适当的运用位运算总是一种迷人的手段,或者当您求职的时候,在代码中写入适当的位运算也会让您的程序增加一丝亮点,最初当我读《编程之美》求“1的数目”时,我才开始觉得位运算是如此之美,后来读到 《Hacker's Delight》,感慨到Henry S.Warren把位运算运用的如此神出鬼没,很多程序都十分精妙,我觉得在一转载 2017-07-08 16:54:26 · 243 阅读 · 0 评论 -
感受异或的神奇
https://www.lijinma.com/blog/2014/05/29/amazing-xor/什么是异或?Wikipedia的解释:在逻辑学中,逻辑算符异或(exclusive or)是对两个运算元的一种逻辑析取类型,符号为 XOR 或 EOR 或 ⊕(编程语言中常用^)。但与一般的逻辑或不同,异或算符的值为真仅当两个运算元中恰有一个的值为真,而另外一个的转载 2017-07-08 16:58:16 · 362 阅读 · 0 评论 -
Leetcode#461. Hamming Distance(异或)
461. Hamming DistanceThe Hamming distance between two integers is the number of positions at which the corresponding ...原创 2017-07-08 16:36:35 · 308 阅读 · 0 评论 -
Leetcode#476. Number Complement(求补码)
Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.Note:The given integer is guaranteed to fit within the range原创 2017-07-09 13:03:15 · 287 阅读 · 0 评论 -
Leetcode# 2. Add Two Numbers(链表模拟大数算法)
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it原创 2017-08-15 21:29:22 · 456 阅读 · 0 评论 -
Leetcode#3. Longest Substring Without Repeating Characters(最长不重复子串-哈希))
Longest Substring Without Repeating CharactersGiven a string, find the length of the longest substring without repeating characters.Examples:Given “abcabcbb”, the answer is “abc”, which the length is 3原创 2017-08-17 09:49:03 · 429 阅读 · 0 评论 -
Leetcode# 1. Two Sum(哈希)
玩了两天生气,又要开始学习啦,打算从leetcode第一道题目开始刷,一周至少三道,其余时间学习项目。保持手感。 不为刷题而刷题,策略是用题号为1的开始顺序刷,对于一道题尝试使用c++和python两种语言多种方法解决问题。开始ing!!!!!!1. Two SumGiven an array of integers, return indices of the two numbers such原创 2017-08-14 11:31:49 · 807 阅读 · 0 评论 -
Leetcode# 136. 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 using extra原创 2017-07-10 19:48:24 · 268 阅读 · 0 评论 -
Leetcode#26. 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 place with co原创 2017-09-13 22:28:04 · 327 阅读 · 0 评论 -
Leetcode#8. String to Integer (atoi)(字符串转数字)
题目Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases原创 2017-08-28 14:05:05 · 474 阅读 · 0 评论 -
Leetcode#5. Longest Palindromic Substring(最长回文子串:二种解法)
题目Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: “babad”Output: “bab”Note: “aba” is also a valid answer.Example:Input:原创 2017-08-26 21:10:57 · 1295 阅读 · 0 评论 -
Leetcode#191. 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 00000000000原创 2017-08-25 15:16:59 · 420 阅读 · 0 评论 -
Leetcode#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 0011100101原创 2017-08-25 11:22:16 · 742 阅读 · 0 评论 -
Leetcode#258. 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 only one di原创 2017-08-22 22:17:14 · 806 阅读 · 0 评论 -
Leetcode#21. Merge Two Sorted Lists (归并排序之单链表)
越来越喜欢leetcode的刷题方式了,只需要写核心的代码,不用为输入输出多一个空格或者少一个空格浪费时间,而且大多题目你需要用vector或者链表解题而不是数组,更加节省空间。题目Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together th原创 2017-08-22 11:42:49 · 616 阅读 · 0 评论 -
Leetcode#9. Palindrome Number(回文数)
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers. Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the in原创 2017-08-19 20:51:30 · 530 阅读 · 0 评论 -
Leetcode# 7. Reverse Integer(位运算)
Reverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321 click to show spoilers. Note: The input is assumed to be a 32-bit signed integer. Your function should ret原创 2017-08-19 17:06:26 · 473 阅读 · 0 评论 -
Leetcode#4.Median of Two Sorted Arrays(归并排序&二分查找求第k小的数)
Median of Two Sorted ArraysThere 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)).Exam原创 2017-08-18 12:01:27 · 702 阅读 · 0 评论 -
Leetcode#20. Valid Parentheses(有效括号-栈)
声明:题目解法使用c++和python两种,练习在于如何将c++代码转换为python代码。题目Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the corr原创 2017-08-28 22:09:03 · 502 阅读 · 0 评论 -
Leetcode#27. Remove Element
题目Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.The ord原创 2017-09-14 15:34:16 · 275 阅读 · 0 评论 -
Leetcode#28. Implement strStr()(String find()函数的用法)
题目Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 题意从字符串haystack找到字符串needle第一次出现的首地址。思路基本思路: 原字符串指针逐步递增,每指向一个字符,从当前字符进行比较原创 2017-09-14 17:03:52 · 450 阅读 · 0 评论 -
Leetcode#35. Search Insert Position
题目Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Her原创 2017-09-14 18:05:31 · 323 阅读 · 0 评论 -
Leetcode#13. Roman to Integer (罗马数字转化阿拉伯数字)
xuna小记:题目解法使用c++和Python两种,重点侧重在于解题思路和如何将解法用python语言实现。题目Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.题意给你一个罗马数字,转换为对应的阿拉伯数字,罗马数字的范围为1~3999。分原创 2017-08-29 12:02:02 · 1165 阅读 · 0 评论 -
Leetcode#12. Roman to Integer (阿拉伯数字转化罗马数字)
xuna小记:题目解法使用c++和Python两种,重点侧重在于解题思路和如何将解法用python语言实现。同类题目:罗马数字转化阿拉伯数字http://blog.youkuaiyun.com/xunalove/article/details/77676382题目Given an integer, convert it to a roman numeral.Input is guaranteed to be w原创 2017-08-29 16:08:37 · 402 阅读 · 0 评论 -
Leetcode#38. Count and Say (模拟)
题目The count-and-say sequence is the sequence of integers with the first five terms as following:1112112111112211 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21. 21 is read off a原创 2017-09-14 22:15:18 · 391 阅读 · 0 评论 -
Leetcode#66. Plus One &&Add Binary (大数)
周末了,说好的每周三道题题目66Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.T原创 2017-09-23 17:51:52 · 287 阅读 · 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] has t原创 2017-09-16 15:43:26 · 653 阅读 · 0 评论 -
Leetcode#58. Length of Last Word
题目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.Note: A word is defined原创 2017-09-16 16:43:08 · 478 阅读 · 0 评论 -
Leetcode#14. Longest Common Prefix (最长公共前缀字符串)
xuna小记:题目解法使用c++和Python两种,重点侧重在于解题思路和如何将解法用python语言实现。题目Write a function to find the longest common prefix string amongst an array of strings. 题意找出最长公共前缀字符串思路找出长度最短的字符串作为模板字符串,枚举模板字符串的每一个字符,比较所有字符串同一位置原创 2017-08-30 20:55:15 · 985 阅读 · 0 评论 -
Leetcode#88. 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) to hold addition原创 2017-09-27 10:54:50 · 267 阅读 · 0 评论 -
Leetcode#100. 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. 题意给你两个二叉树p和q,写一个原创 2017-09-27 12:29:08 · 696 阅读 · 0 评论 -
Leetcode#101. Symmetric Tree(对称树)
题意Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But th原创 2017-09-27 20:22:31 · 321 阅读 · 0 评论 -
Leetcode#104. 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.题意给你一个二叉树,求出二叉树的最大的深度。分析递归模型为:f(root)==0原创 2017-09-27 20:55:26 · 311 阅读 · 0 评论 -
Leetcode#107. Binary Tree Level Order Traversal II (queue二叉树层次遍历)
题目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,null,null,15,7原创 2017-10-09 20:14:49 · 459 阅读 · 0 评论