【LeetCode从零单排】No14.LongestCommonPrefix
题目
代码
public class Solution {public String longestCommonPrefix(String[] strs) {if(strs.length==0) return "";if(strs.length==1) return strs[0];String commonPrefix="";boolean end=true;char strChar[]=strs[0].toCharArray();ok:for (int j = 0;j<strChar.length;j++){for(int i=1;i<strs.length;i++){char tempChar[]=strs[i].toCharArray();int tempChar_length=tempChar.length;if(j<tempChar_length){if(tempChar[j]==strChar[j]){}else{break ok; }}else{break ok;}} commonPrefix+=strChar[j];}return commonPrefix;}
}
/********************************
* 本文来自博客 “李博Garvin“
* 转载请标明出处:http://blog.csdn.net/buptgshengod
******************************************/
【LeetCode从零单排】No14.LongestCommonPrefix相关推荐
- 【LeetCode从零单排】No198.House Robber No91.Decode Ways139 word break(动态规划典型应用)
1.题目 一道典型的Dynamic Programming的题目. You are a professional robber planning to rob houses along a stree ...
- 【LeetCode从零单排】No70.ClimbingStairs
题目 爬楼梯问题,这是一道很有趣的问题.首先看题目: You are climbing a stair case. It takes n steps to reach to the top. Each ...
- 【LeetCode从零单排】No26.Remove Duplicates from Sorted Array
题目 题目要求:去除sort int数组中的重复项. Given a sorted array, remove the duplicates in place such that each ...
- 【LeetCode从零单排】No.7 Reverse Integer
前话 今天开始励志刷一下leetcode上面的题目(还好这个网站没被TG和谐).从easy的开始,数一下差不多有40道,争取两个月搞定. 题目 没想到做的第一道题目,虽然看似 ...
- 【LeetCode从零单排】No.135Candy(双向动态规划)
1.题目 There are N children standing in a line. Each child is assigned a rating value. You are giving ...
- 【LeetCode从零单排】No22.Generate Parentheses
题目 Given n pairs of parentheses, write a function to generate all combinations of well-formed parent ...
- 【LeetCode从零单排】No221.Maximal Square
题目 Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ...
- 【LeetCode从零单排】No133. clon graph (BFS广度优先搜索)
背景 (以下背景资料转载自:http://www.cnblogs.com/springfor/p/3874591.html?utm_source=tuicool) DFS(Dpeth-first Se ...
- 【LeetCode从零单排】No121 Best Time to Buy and Sell Stock
题目 Say you have an array for which the ith element is the price of a given stock on day i. If you we ...
最新文章
- 隐马尔科夫模型HMM(一)HMM模型
- 代码 设计 生活 (2)--- 菜鸟
- 用matlab编辑器打开.m文件
- 基于Node的Koa2项目从创建到打包到云服务器指南
- js异步加载 defer和async 比较
- 论程序员如何规划职业路线?网友:从码农到工程师?
- vue中$watch源码阅读笔记
- 一个 union all 的all
- VS2013的一些常用快捷键
- 天勤2022数据结构(二)栈和队列
- 机器学习(周志华) 第十六章强化学习
- 生物信息学 之 序列比对
- 北大公开课计算机,清华、北大、浙大的计算机课程资源集都在这里了
- 《清单革命》:让大脑处理更重要的事情
- Kermit,Xmodem,1K-Xmodem,Ymodem,Zmodem传输协议小结
- 全差分运算放大器浅析
- AWVS扫描web站点
- kuka机器人offset指令_KUKA机器人MADA详解.doc
- 2-appium之adb介绍
- CEPH分布式存储介绍与原理架构概述
热门文章
- PAT甲级1139 First Contact (30 分):[C++题解] 图论、暴力枚举两个点、hash映射
- mysql主从同步默认延迟_减少mysql主从数据同步延迟问题的详解
- 易语言开发c s,Grid++Report报表工具C/S实战项目演练
- python如何下载tushare_安装tushare
- python逻辑运算符不懂_Python运算符之逻辑运算符
- c++ opencv编程实现暗通道图像去雾算法_OpenCV图像处理专栏十五 |一种基于亮度均衡的图像阈值分割技术...
- oracle中dlink使用,Oracle,MetaLink,中文使用指南
- a eraser eraser还是an_eraser前面用a还是an
- win10怎么用Linux命令,教你Windows10系统使用Linux命令的技巧
- orm mysql_ORM介绍