![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
绯浅yousa
欢迎转载。文章偏基础较多---》因为写起来快,但是也会坚持出好文章
展开
-
leetcode: 231.Power of Two(另一种特殊求法)
231. Power of Two(另一种特殊求法)Given an integer, write a function to determine if it is a power of two.这里个人想到三种解法第一种一种是求这个数的以2为底的对数,然后取整数部分,作2的乘方,看是否相等class Solution(object): def isPowerOfTwo(self, n):原创 2016-04-06 23:12:15 · 401 阅读 · 0 评论 -
leetcode205. isomorphic strings
leetcode205. Isomorphic Stringshash思维Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a characte原创 2016-08-15 23:21:11 · 348 阅读 · 0 评论 -
leetcode217. contains duplicate
leetcode217. Contains DuplicateGiven 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 re原创 2016-08-15 23:21:34 · 255 阅读 · 0 评论 -
leetcode371. sum of two integers
leetcode371. Sum of Two IntegersCalculate 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.这个就是基本的加法器(ALU)工作行为。如果是单比特的a + b,那原创 2016-08-15 23:22:59 · 292 阅读 · 0 评论 -
atonum
Atonum忘记哪道题了。。。int charToNumber(char c) { if (c <= 'Z' && c >= 'A') { return c - 'A' + 1; } else if (c <= 'z' && c >= 'a'){ return c - 'a' + 1; } return 0;}int title原创 2016-08-15 23:23:29 · 293 阅读 · 0 评论 -
leetcode206. reverse linked list
leetcode206. Reverse Linked ListReverse a singly linked list.click to show more hints.Hint: A linked list can be reversed either iteratively or recursively. Could you implement both?没啥难度,主要是要求逻辑清晰type原创 2016-08-15 23:23:53 · 305 阅读 · 0 评论 -
136. Single Number
136. Single Number问题描述Given an array of integers, every element appears twice except for one. Find that single one.解决思路1、目标要求是线性时间,那么基本不能用遍历了。可以考虑计算机提供的特殊运算2、考虑到两个相同的数异或运算会等于零,然后所有数异货就会剩下唯一的数思路就是这样代码fu原创 2016-11-17 23:47:33 · 343 阅读 · 0 评论 -
453. Minimum Moves to Equal Array Elements
453. Minimum Moves to Equal Array ElementsQuesetion:Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n原创 2016-11-22 00:26:27 · 535 阅读 · 0 评论 -
463. Island Perimeter
463. Island PerimeterYou are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The原创 2017-02-06 23:59:12 · 344 阅读 · 0 评论 -
268. Missing Number
268. Missing NumberGiven 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原创 2017-02-23 01:06:58 · 286 阅读 · 0 评论 -
leetcode 202. happy number
leetcode 202. Happy NumberWrite 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 t原创 2016-08-15 23:20:39 · 296 阅读 · 0 评论 -
leetcode 191. number of 1 bits
leetcode 191. Number of 1 BitsWrite 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 binar原创 2016-08-15 23:20:09 · 358 阅读 · 0 评论 -
(go语言)263.uglynumber
(Go语言)263.UglyNumber好像就是算因数有没有2、3、5以外的因数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 a原创 2016-06-21 00:05:16 · 290 阅读 · 0 评论 -
leetcode: Power of Three
Power of ThreeGiven 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?给一个整数,判断其是否是3的幂,要求不可以有迭代和循环从数学的角度想,可以先求这个数的3的对数,取整数,原创 2016-04-06 23:12:52 · 306 阅读 · 0 评论 -
leetcode-292.Nim Game
leetcode-292.Nim GameYou 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 la原创 2016-03-25 12:14:11 · 393 阅读 · 0 评论 -
leetcode-258.add digits/Digital root
leetcode-258.Add DigitsGiven 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原创 2016-03-26 08:54:34 · 535 阅读 · 0 评论 -
leetcode: 226. Invert Binary Tree
leetcode: 226. Invert Binary TreeInvert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1没啥好说的/** * Definition for a binary tree node.原创 2016-04-08 22:58:43 · 277 阅读 · 0 评论 -
leetcode: 237. Delete Node in a Linked List
leetcode: 237. Delete Node in a Linked ListWrite 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 y原创 2016-04-08 23:38:41 · 446 阅读 · 0 评论 -
【leetcode】283.move_zeroes
【leetcode】283.Move ZeroesGiven 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],原创 2016-07-10 22:40:01 · 332 阅读 · 0 评论 -
go反转字符串
Go反转字符串似乎没什么好办法,string的话也得需要先转换成rune再反转再转成stringpackage mainimport ( "fmt")func reverseString(s string) string { runes := []rune(s) for from, to := 0, len(runes)-1; from < to; from, to原创 2016-06-19 23:19:32 · 3255 阅读 · 0 评论 -
go语言reversevowelsofastring
Go语言ReverseVowelsofaString主要是判断是不是元音字符,没啥难度,记得实际写的时候要去掉魔鬼数字package mainimport ( "fmt" )//注意考虑大小写func isVowel(vowel rune) bool { if vowel == 97 || vowel == 97-32 { return true }原创 2016-06-19 23:20:19 · 474 阅读 · 0 评论 -
(go语言)242.validanagram
(Go语言)242.ValidAnagram用数组统计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.原创 2016-06-21 00:04:59 · 294 阅读 · 0 评论 -
461. Hamming Distance leet-code
461. Hamming Distance leet-code题目介绍The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Hamming d原创 2017-02-03 00:24:54 · 299 阅读 · 0 评论