![](https://img-blog.csdnimg.cn/20190927151132530.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
LeetCode
__KevinYzy__
github:https://github.com/KEVINYZY ----
leetcode:https://leetcode.com/seanadfgfeer/ ----
lintcode:https://www.lintcode.com/user/fire-blade ----
nowcoder:https://www.nowcoder.com/profile/1073818
展开
-
Leetcode 959. Regions Cut By Slashes
并查集class Solution {private: int _fa[3600]; int N, M; void init() { for (int i = 0; i < M; i++) _fa[i] = i; } int fa(int x) { return x == _fa[...原创 2019-05-19 10:32:32 · 167 阅读 · 0 评论 -
Leetcode 345. Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Given s = "hello", return "holle".Example 2:Given s = "leetcode", return "leotcede".Note:The v...原创 2017-03-28 21:17:13 · 221 阅读 · 0 评论 -
Leetcode 342. 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: Could you solve it without loop...原创 2017-03-28 21:16:27 · 211 阅读 · 0 评论 -
Leetcode 198. 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 adjacent house...原创 2017-03-28 21:15:02 · 202 阅读 · 0 评论 -
Leetcode 235. 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 thedefinition of LCA on Wikipedia: “The lowest common ancestor is defined betw原创 2017-03-28 21:09:55 · 273 阅读 · 0 评论 -
Leetcode 21. Merge Two Sorted Lists
Merge 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.# Definition for singly-linked list.# class ListNode(原创 2017-03-28 21:08:50 · 212 阅读 · 0 评论 -
Leetcode 263. Ugly Number
Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include2, 3, 5. For example,6, 8are ugly while14is not ugly sinc原创 2017-03-28 21:07:39 · 198 阅读 · 0 评论 -
Leetcode 107. Binary Tree Level Order Traversal II
Given a binary tree, return thebottom-up level ordertraversal 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,1原创 2017-03-28 21:06:54 · 210 阅读 · 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 theHamming weight).For example, the 32-bit integer ’11' has binary representation000000原创 2017-03-28 21:04:49 · 261 阅读 · 0 评论 -
Leetcode 70. Climbing Stairs
You are climbing a stair case. It takesnsteps 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?Note:Givennwill be a posi原创 2017-03-28 21:03:54 · 194 阅读 · 0 评论 -
Leetcode 83. Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, return1->2->3.# Definition for si原创 2017-03-28 21:03:03 · 206 阅读 · 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...原创 2017-03-28 21:18:13 · 283 阅读 · 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 3原创 2017-03-28 21:20:40 · 296 阅读 · 0 评论 -
Leetcode 226. Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired bythis original tweetbyMax Howe原创 2017-03-26 23:30:08 · 187 阅读 · 0 评论 -
Leetcode 389. Find the Difference
Given two stringssandtwhich consist of only lowercase letters.Stringtis generated by random shuffling stringsand then add one more letter at a random position.Find the letter that was原创 2017-03-26 23:27:15 · 216 阅读 · 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.# Definition for a binary tr原创 2017-03-26 23:26:04 · 178 阅读 · 0 评论 -
Leetcode 136. Single Number
Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using e原创 2017-03-26 23:24:31 · 187 阅读 · 0 评论 -
Leetcode 292. Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the原创 2017-03-26 23:22:15 · 179 阅读 · 0 评论 -
Leetcode 344. Reverse String
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".class Solution(object): def reverseString(self, s):原创 2017-03-26 23:20:17 · 189 阅读 · 0 评论 -
Leetcode 412.Fizz Buzz
Write a program that outputs the string representation of numbers from 1 ton.But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. Fo...原创 2017-03-26 23:17:41 · 238 阅读 · 0 评论 -
Leetcode 110. 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 tree in which the depth of the two subtrees ofeverynode never differ...原创 2017-03-28 21:24:10 · 298 阅读 · 0 评论 -
Leetcode 118. Pascal's Triangle
GivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]class Solution(object): ...原创 2017-03-28 21:23:10 · 260 阅读 · 0 评论 -
Leetcode 66. Plus One
Given a non-negative integer represented as anon-emptyarray of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The digits ...原创 2017-03-28 21:21:30 · 261 阅读 · 0 评论 -
Leetcode 231. Power of Two
Given an integer, write a function to determine if it is a power of two.Credits:Special thanks to@jianchao.li.fighterfor adding this problem and creating all test cases.class Solution原创 2017-03-28 21:02:23 · 233 阅读 · 0 评论 -
Leetcode 326. 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?class Solution {public: bool isPowerOfThree(int原创 2017-03-28 21:01:32 · 203 阅读 · 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.# Definiti原创 2017-03-27 22:27:33 · 253 阅读 · 0 评论 -
Leetcode 237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is1 -> 2 -> 3 -> 4and you are given the third node with value原创 2017-03-27 22:26:04 · 176 阅读 · 0 评论 -
Leetcode 171. Excel Sheet Column Number
Related to questionExcel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ...原创 2017-03-27 22:25:17 · 177 阅读 · 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.Note:原创 2017-03-27 22:24:17 · 295 阅读 · 0 评论 -
Leetcode 349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection.Example:Givennums1=[1, 2, 2, 1],nums2=[2, 2], return[2].Note:Each element in the result must be unique.The res原创 2017-03-27 22:23:22 · 185 阅读 · 0 评论 -
Leetcode 404. Sum of Left Leaves
Find the sum of all left leaves in a given binary tree.Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24原创 2017-03-27 22:22:26 · 205 阅读 · 0 评论 -
Leetcode 383. Ransom Note
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; ot原创 2017-03-27 22:21:11 · 197 阅读 · 0 评论 -
Leetcode 167. Two Sum II - Input array is sorted
Given an array of integers that is alreadysorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two number原创 2017-03-27 22:20:02 · 175 阅读 · 0 评论 -
Leetcode 283. Move Zeroes
Given an arraynums, write a function to move all0's to the end of it while maintaining the relative order of the non-zero elements.For example, givennums = [0, 1, 0, 3, 12], after calling you原创 2017-03-27 22:19:09 · 189 阅读 · 0 评论 -
leetcode上令人拍案叫绝的解法
作者:努力的摩羯链接:https://www.zhihu.com/question/35485418/answer/63609637来源:知乎著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。1. 279 Perfect Squares【题意】给定一个数,求其最少能表示成几个完全平方数的和表示。【思路】用动归解决。【别人家的小孩】4ms C++转载 2017-03-27 22:17:54 · 1578 阅读 · 0 评论 -
Leetcode 169. Majority Element
Given an array of sizen, find the majority element. The majority element is the element that appearsmore than⌊ n/2 ⌋times.You may assume that the array is non-empty and the majority element原创 2017-03-27 22:28:51 · 198 阅读 · 0 评论 -
Leetcode 242. Valid Anagram
Given two stringssandt, write a function to determine iftis an anagram ofs.For example,s= "anagram",t= "nagaram", return true.s= "rat",t= "car", return false.Note:You may ass原创 2017-03-27 22:29:40 · 177 阅读 · 0 评论 -
Leetcode 202. 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 squares原创 2017-03-28 20:58:48 · 210 阅读 · 0 评论 -
Leetcode 121. Best Time to Buy and Sell Stock
Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),原创 2017-03-28 20:57:10 · 191 阅读 · 0 评论 -
Leetcode 405. Convert a Number to Hexadecimal
Given an integer, write an algorithm to convert it to hexadecimal. For negative integer,two’s complementmethod is used.Note:All letters in hexadecimal (a-f) must be in lowercase.The hexade原创 2017-03-28 20:56:27 · 196 阅读 · 0 评论