- 博客(18)
- 收藏
- 关注
原创 LeetCode-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.Example...
2018-04-27 15:31:57 162
原创 LeetCode-Move_Zeroes
题目:Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling your f...
2018-04-27 14:23:01 98
原创 LeetCode-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 on ...
2018-04-26 14:44:13 149
原创 LeetCode-Missing_Number
题目:Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.Example 1Input: [3,0,1]Output: 2Example 2Input: [9,6,4,2,3,5,7,0,1]Output: 8...
2018-04-26 13:39:12 130
原创 LeetCode-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 since i...
2018-04-25 10:53:31 172
原创 LeetCode-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 digi...
2018-04-25 10:29:48 112
原创 LeetCode-Binary_Tree_Paths
题目:Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]翻译:给定一个二叉树,返回从根到叶子的...
2018-04-24 14:49:12 107
原创 LeetCode-Valid_Anagram
题目: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 the str...
2018-04-24 13:46:41 124
原创 LeetCode-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 is 1 -> 2 -> 3 -> 4 and you are given the third node wi...
2018-04-19 16:30:36 126
原创 LeetCode-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 between...
2018-04-18 19:48:39 125
原创 LeetCode-Palindrome_Linked_List
题目:Given a singly linked list, determine if it is a palindrome.翻译:给定一个单链表,判断它是否回文。思路:要判断是否回文,很容易想到利用栈来判断,前一半入栈,从而与后一半相比较。因此对于一个给定的单链表,首先判断它含有的节点个数,若含有节点数为偶数,那么先将前一半的节点value值压入栈中,利用链表后一半的节点value值与栈中元素进...
2018-04-17 14:02:50 142
原创 LeetCode-Implement_Queue_using_Stacks
题目:Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front element.empty()...
2018-04-16 21:03:16 129
原创 LeetCode-Power_of_Two
题目:Given an integer, write a function to determine if it is a power of two.翻译:给定一个数字,写一个函数判断它是否为2的幂。思路:给定一个数字n,若它是2的幂,那么转换为二进制的表示为 1 后跟随若干 0 ,于是可以利用 n & (n-1) 来判断 n 是否为2的幂。若 n & (n-1) 结果为0,则 n...
2018-04-13 09:17:30 148
原创 LeetCode-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() -- Return wheth...
2018-04-11 09:43:23 210
原创 LeetCode-Invert_Binary_Tree
题目:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1翻译:翻转一颗二叉树。 4 / \ 2 7 / \ / \1 3 6 9到 4 / \ ...
2018-04-11 09:13:22 130
原创 LeetCode-Contains_Duplicate_II
题目: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 absolute difference between i and j is at most ...
2018-04-08 10:32:20 130
原创 LeetCode-Contains_Duplicate
题目: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 element...
2018-04-03 09:16:20 128
原创 LeetCode-Reverse_Linked_List
题目:Reverse a singly linked list.翻译:掉转一个单链表。思路:利用栈的后进先出,先将链表中的各元素压入栈中,再取出即得到掉转的单链表(注意:1.链表是否含头节点;2.对空链表进行判断)。C++代码(Visual Studio 2017):#include "stdafx.h"#include <iostream>#include <vector&...
2018-04-02 11:19:54 121
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人