算法
YatKam
成长在于积累,分享是种美德!
展开
-
java 小项目:简单扑克牌游戏
项目要求 1>新建两个玩家 2>创建扑克牌,洗牌 3>发牌,每个玩家没人拿两张,比较大小 4>比较规则:两个玩家选出各种最大的牌,进行游戏,先比较点数大小,点数大的获胜,点数相同则比较花色:黑桃>红心>梅花>方块 5>输出要求:结束时分别输出玩家的手牌情况。运行结果截图: Java源码: Card类:package com.card;import java.util.ArrayLis原创 2015-05-27 05:44:38 · 7712 阅读 · 1 评论 -
LeetCode解题报告--2Sum, 3Sum, 4Sum, K Sum求和问题总结
前言: 这几天在做LeetCode 里面有2sum, 3sum(closest), 4sum等问题, 这类问题是典型的递归思路解题,该这类问题的关键在于,在进行求和求解前,要先排序Arrays.sort()可实现,而本文则着重探讨关于KSum问题。 leetcode求和问题描述(K sum problem): K sum的求和问题一般是这样子描述的:给你一组N个数字(比如 vector原创 2015-08-17 18:22:02 · 3681 阅读 · 0 评论 -
LeetCode解题报告--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.N原创 2015-06-05 05:28:49 · 766 阅读 · 0 评论 -
LeetCode解题报告---Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321原题出处:https://leetcode.com/problems/reverse-integer/解题思路:如果输入”100”,”10000”,反转之后输出时应考虑前导‘0’;输入溢出时时以及反转输出时溢出直接原创 2015-06-03 03:55:18 · 640 阅读 · 0 评论 -
LeetCode解题报告--ZigZag Conversion
题目来源:https://leetcode.com/problems/zigzag-conversion/P AH N AP LS I I G YI R 解法一: 间距为: icount = 2 * (nRows - 1) 每列的字符个数为:i = nRows[from 0 to (nRows - 1)] 中间未加粗字符其下标为: mid = j + icount - 2 * i原创 2015-06-02 00:04:47 · 706 阅读 · 0 评论 -
LeetCode解题报告--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, and there exists one unique longest palindromic substring. 题目来源:https://leetcode.com原创 2015-05-17 16:15:36 · 785 阅读 · 0 评论 -
LeetCode解题报告-- Count and Say
题目: The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, … 1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21. 21 is read原创 2015-12-03 15:05:12 · 2613 阅读 · 1 评论 -
LeetCode解题报告--Next Permutation
题目: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest pos原创 2015-12-03 20:54:30 · 1838 阅读 · 1 评论 -
LeetCode解题报告--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 a原创 2015-12-04 16:58:11 · 1806 阅读 · 0 评论 -
LeetCode解题报告--Search for a Range
题目: Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm’s runtime complexity must be in the order of O(log n). If the target is not f原创 2015-12-04 13:32:03 · 2410 阅读 · 0 评论 -
LeetCode解题报告--Combination Sum II
题目: Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. Each number in C may only be used once in the comb原创 2015-12-07 21:10:15 · 1173 阅读 · 0 评论 -
LeetCode解题报告--Letter Combinations of a Phone Number
题目:字母组合的电话号码 Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below. Input:D原创 2015-08-17 17:43:42 · 2463 阅读 · 0 评论 -
LeetCode解题报告--4Sum
题目: 4Sum Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: Elements原创 2015-08-17 17:54:37 · 889 阅读 · 0 评论 -
LeetCode解题报告--3 Sum
题目: 3 个数和问题 Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: Elements in a triplet (a,b原创 2015-08-16 16:37:27 · 1499 阅读 · 1 评论 -
基于双链表 实现Java Queue队列
除了可以通过一维数组,单链表实现queue队列,还可以通过双链表实现queue队列。在基于NLNode类实现双向链表的时候,为了使编程更加简洁,通常我们都要在最前端和最后端各设置一个哑元节点( Dummy node )。这两个节点分别称作头节点( Header node )和尾节点( Trailer node) ㈠,起哨兵( Sentinel)的作用。也就是说,它们并不存储任何实质的数据对象,头(尾原创 2015-06-14 21:02:58 · 925 阅读 · 0 评论 -
LeetCode解题报告--Container With Most Water
题目:最大的盛水容器Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fi原创 2015-08-13 17:37:37 · 795 阅读 · 0 评论 -
LeetCode解题报告--Palindrome Number
题目:回文数字的判断 Determine whether an integer is a palindrome. Do this without extra space.Some hints: Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to strin原创 2015-08-13 17:28:51 · 1492 阅读 · 0 评论 -
LeetCode解题报告--Integer to Roman
题目:阿拉伯数字转罗马数字Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999.原题链接地址:https://leetcode.com/problems/integer-to-roman/ 分析:题意将阿拉伯数字num转罗马数字 拼写原创 2015-08-13 19:39:20 · 899 阅读 · 0 评论 -
Reverse Integer 解题报告
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321原题出处:https://leetcode.com/problems/reverse-integer/解题思路:如果输入”100”,”10000”,反转之后输出时应考虑前导‘0’;输入溢出时时以及反转输出时溢出直接原创 2015-06-03 01:31:45 · 692 阅读 · 0 评论 -
LeetCode解题报告--Roman to Integer
题目:罗马数字转为阿拉伯数字 Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999. 分析:题意:将给定的罗马数字转为阿拉伯数字 从前往后遍历罗马数字,如果某个数比前一个数小,则把该数加入到结果中; 反之,则在结果中两次减去前一个数并加原创 2015-08-13 19:46:54 · 965 阅读 · 0 评论 -
LeetCode解题报告--Longest Common Prefix
题目:最长公共前缀 Write a function to find the longest common prefix string amongst an array of strings.分析:题意找出所有字符串的最长公共前缀。 思路简单:如下步骤 1. 找出字符串数组中字符串长度最小的字符串minStr 2. minStr与其余的字符串逐个字符比较,确定最长公共前缀java 代码:(a原创 2015-08-14 15:43:40 · 1544 阅读 · 0 评论 -
树结构的自定义及基本算法(Java数据结构学习笔记)
数据结构可以归类两大类型:线性结构与非线性结构,本文的内容关于非线性结构:树的基本定义及相关算法。关于树的一些基本概念定义可参考:维基百科 树的ADT模型: 根据树的定义,每个节点的后代均构成一棵树树,称为子树。因此从数据类型来讲,树、子树、树节点是等同地位,可将其看作为一个节点,用通类:Tree表示。如下图所示: 图:Tree ADT模型示意图 可采用“父亲-儿子-兄弟”模型来表示树的原创 2015-08-16 20:07:26 · 7259 阅读 · 0 评论 -
LeetCode解题报告--3Sum Closest
题目:与3数和最接近的和 Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would原创 2015-08-16 16:46:24 · 1010 阅读 · 0 评论 -
LeetCode解题报告--Combination Sum
题目: Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number may be chosen from C unlimited n原创 2015-12-07 20:24:31 · 1069 阅读 · 1 评论