본문 바로가기

개발자도전

검색하기
개발자도전
프로필사진 도do

  • 분류 전체보기 (102)
    • Java (4)
    • HTML (10)
    • CSS3 (21)
    • 프로그래머스 코딩 테스트 (51)
    • LeetCode (13)
    • 팜팜 프로젝트 (3)
Guestbook
Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
일 월 화 수 목 금 토
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Tags
more
Archives
Today
Total
관리 메뉴
  • 글쓰기
  • 방명록
  • RSS
  • 관리

목록LeetCode (13)

개발자도전

[LeetCode] Max Consecutive Ones

[문제] Given a binary array nums, return the maximum number of consecutive 1's in the array. 1이 연속되서 나타날 시 반복된 횟수의 최대값 구하기. 예 1. Input: nums = [1,1,0,1,1,1] Output: 3 예 2. Input: nums = [1,0,1,1,0,1] Output: 2 [답] for문을 사용해 nums 배열의 값들을 하나씩 빼왔다. 그 값이 1이라면 count를 1 더해주고, 1이 아니라면 max값과 count값을 Math.max함수에 넣어 더 큰 값을 max값에 대입될 수 있도록 적어주었다. 또한 1이 아니라면 count값은 다시 0이 되도록 해주고 max값을 return 시켜주었다.

LeetCode 2023. 1. 19. 20:31
이전 Prev 1 2 3 Next 다음

Blog is powered by kakao / Designed by Tistory

티스토리툴바