随笔分类 -  leetcode-easy

记录leetcode的刷题之旅,从easy开始
摘要:题目 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 s 阅读全文
posted @ 2018-10-17 09:36 shinjia 阅读(108) 评论(0) 推荐(0)
摘要:题目 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 le 阅读全文
posted @ 2018-10-17 09:32 shinjia 阅读(94) 评论(0) 推荐(0)
摘要:题目 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. Example: Inpu 阅读全文
posted @ 2018-10-17 09:29 shinjia 阅读(84) 评论(0) 推荐(0)
摘要:题目 You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the qualit 阅读全文
posted @ 2018-10-17 09:24 shinjia 阅读(94) 评论(0) 推荐(0)
摘要:题目 Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. Example 1: Input: [3,0,1] Out 阅读全文
posted @ 2018-10-15 10:59 shinjia 阅读(89) 评论(0) 推荐(0)
摘要:题目 Given a binary tree, return all root to leaf paths. Note: A leaf is a node with no children. Example: Input: 1 / \ 2 3 \ 5 Output: ["1 2 5", "1 3"] 阅读全文
posted @ 2018-10-15 10:14 shinjia 阅读(155) 评论(0) 推荐(0)
摘要:题目 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. Exam 阅读全文
posted @ 2018-10-15 09:00 shinjia 阅读(77) 评论(0) 推荐(0)
摘要:题目 Given a non negative integer num, repeatedly add all its digits until the result has only one digit. Example: Input: 38 Output: 2 Explanation: The 阅读全文
posted @ 2018-10-15 08:40 shinjia 阅读(91) 评论(0) 推荐(0)
摘要:题目 Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Given linked list head = [4,5,1,9], wh 阅读全文
posted @ 2018-10-14 11:20 shinjia 阅读(101) 评论(0) 推荐(0)
摘要:题目 Given an integer, write a function to determine if it is a power of two. Example 1: Input: 1 Output: true Explanation: 20 = 1 Example 2: Input: 16 阅读全文
posted @ 2018-10-14 11:06 shinjia 阅读(106) 评论(0) 推荐(0)
摘要:题目 Invert a binary tree. 比如原来的树为 0 1 2 逆转后的树为 0 2 1 也就是把所有结点的左右结点互换 解法一 思路 递归 代码 解法二 思路 非递归,用树的层次遍历 代码 阅读全文
posted @ 2018-10-14 10:36 shinjia 阅读(83) 评论(0) 推荐(0)
摘要:题目 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 t 阅读全文
posted @ 2018-10-14 10:06 shinjia 阅读(85) 评论(0) 推荐(0)
摘要:题目 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 阅读全文
posted @ 2018-10-14 09:38 shinjia 阅读(92) 评论(0) 推荐(0)
摘要:题目 Reverse a singly linked list. Example: Input: 1 2 3 4 5 NULL Output: 5 4 3 2 1 NULL Follow up: A linked list can be reversed either iteratively or 阅读全文
posted @ 2018-10-14 09:11 shinjia 阅读(78) 评论(0) 推荐(0)
摘要:题目 Count the number of prime numbers less than a non negative number, n. Example: Input: 10 Output: 4 Explanation: There are 4 prime numbers less than 阅读全文
posted @ 2018-10-12 11:59 shinjia 阅读(90) 评论(0) 推荐(0)
摘要:题目 Remove all elements from a linked list of integers that have value val. Example: Input: 1 2 6 3 4 5 6, val = 6 Output: 1 2 3 4 5 解法 思路 思路不难。。。就是很繁琐 阅读全文
posted @ 2018-10-12 10:16 shinjia 阅读(116) 评论(0) 推荐(0)
摘要:题目 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 int 阅读全文
posted @ 2018-10-12 09:26 shinjia 阅读(126) 评论(0) 推荐(0)
摘要:题目 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 阅读全文
posted @ 2018-10-12 08:27 shinjia 阅读(148) 评论(0) 推荐(0)
摘要:题目 Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight). Example: Input: 11 Ou 阅读全文
posted @ 2018-10-11 11:08 shinjia 阅读(102) 评论(0) 推荐(0)
摘要:题目 Reverse bits of a given 32 bits unsigned integer. Example: Input: 43261596 Output: 964176192 Explanation: 43261596 represented in binary as 0000001 阅读全文
posted @ 2018-10-11 10:57 shinjia 阅读(88) 评论(0) 推荐(0)